myITforum.com Community Forum myITforum.com Community Forum

Home  Forums  Blogs  Live Support chat  Search Articles  Wiki  FAQ  Email Lists  Register  Login  My Profile  Inbox  Address Book  My Subscription  My Forums 

Photo Gallery  Member List  Search  Calendars  FAQ  Ticket List  Log Out

All Forums RSS Feed Subscription:


  


Help me with my VBScript to monitor my computers harddisk, cpu and memory

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
  Printable Version
All Forums >> [Scripting Technologies] >> VB Script >> Help me with my VBScript to monitor my computers harddisk, cpu and memory Page: [1]
Login
Message << Older Topic   Newer Topic >>
Help me with my VBScript to monitor my computers harddi... - 6/13/2008 2:29:21 AM   
jeffablang

 

Posts: 4
Score: 0
Joined: 6/13/2008
Status: offline
Hi, I am just a newbie in scripting and I'm having a hard time on this thing that i'm doing.  I just want some help from you guys which i know are expert in this. I just want to ask if anyone of you can help me with the script i need to monitor my computers hard disk space, my cpu usage in (%) and memory RAM usage in (%).  I will surely appreciate if you can help me with this one. My OS is windows XP and windows 2000

I made a script but when I run it has an error can someone help me with my problem. All i want is to get the Hard Disk Space, Memory Usage and CPU Usage. the output could be a log file *.txt format of in microsoft excel *.xls file.

VBScript Code:
 
strComputerName = GetCurrentComputerName ' get name only once for performance reasons
subject = "Drive Space Report " & strComputerName
str = str & Date() & Space(2) & Time() & vbcrlf & vbcrlf
str = str & strComputerName & vbcrlf
str = str & GetFreeSpaceReport
strComputer = "."

 
' Constants for drive types
Const Unknown = 0
Const Removable = 1
Const Fixed = 2
Const Remote = 3
Const CDROM = 4
Const RAMDisk = 5

 
' get current computer name (from system environment variables)
Function GetCurrentComputerName
         Set oWsh = WScript.CreateObject("WScript.Shell")
         Set oWshSysEnv = oWsh.Environment("PROCESS")
         GetCurrentComputerName = oWshSysEnv("COMPUTERNAME")
End Function

 
'Get free space report
Function GetFreeSpaceReport
         Set oFs = WScript.CreateObject("Scripting.FileSystemObject")
         Set oDrives = oFs.Drives
          For Each oDrive In oDrives
         Select Case oDrive.DriveType
      Case Fixed
GetFreeSpaceReport = GetFreeSpaceReport & oDrive.DriveLetter & ": " & Round(oDrive.FreeSpace/(1024*1024)) & "MB free (" & Round(100 * (oDrive.FreeSpace/oDrive.TotalSize),2) & "%)" & vbcrlf
End Select
Next
End Function


'Gets CPU Processor Speed
strComputer = "."
        Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
        Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name = '_Total'")
For Each objItem In colItems
WScript.Echo objItem.PercentProcessorTime
Next


'Get CPU Memory Usage Status"
Sub TestMemoryStatus
Dim Mem
           Set Mem = Win32API.TMemoryStatus
                Mem.dwLength = 32
           Win32API.GlobalMemoryStatus Mem
           Log.Message "MEMORYSTATUS test", _
           "Percent of memory in use - " + _
         CStr(Mem.dwMemoryLoad)
End Sub

 
'Output to text
Set objFSO = CreateObject("Scripting.FileSystemObject" & "%")
Set objOutFile = objFSO.OpenTextFile("D:\Server_hdd_cpu_mem.txt", 8, True)

 
strLine = str
 
objOutFile.WriteLine strLine
 
Output To screen - useful For debugging
MsgBox "Hard Disk Space, Memory and CPU UsageChecking DONE"


==================================================

Thank You!

Jeff
Post #: 1
RE: Help me with my VBScript to monitor my computers ha... - 6/13/2008 6:43:07 PM   
rbennett806


Posts: 786
Score: 13
Joined: 6/14/2006
Status: offline
Well first off, you might try searching for "VBScript" and "inventory" out on the web to see various pieces of information on what you can gather. I kind of cleaned up and rearranged your script because it looks like it was doing some different things using different methods (and you had a lot of extra variables and overhead). So I tried to leave things named the same so you can use it to learn how you can trim down the code.

So try this and see if it helps you get a grip on some things...
Option Explicit

Dim oWsh, oWshSysEnv, objFSO, objWMIService
Dim oDrives, oDrive, objOutFile, colItems, objItem
Dim strLineTime, strLineProcessorTime, strLineDriveSpace

Set oWsh = WScript.CreateObject("WScript.Shell")
Set oWshSysEnv = oWsh.Environment("PROCESS")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")

strLineTime = Date() & Space(2) & Time()

'Gets CPU Processor Speed
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name = '_Total'")
For Each objItem In colItems
   strLineProcessorTime = strLineProcessorTime & " " & objItem.PercentProcessorTime
Next

'Get free space report
Set oDrives = objFSO.Drives
For Each oDrive In oDrives
   Select Case oDrive.DriveType
   Case 2 'Fixed Drives
   strLineDriveSpace = strLineDriveSpace & " " & oDrive.DriveLetter & "\: " & Round(oDrive.FreeSpace/(1024*1024)) & "MB free (" & Round(100 * (oDrive.FreeSpace/oDrive.TotalSize),2) & "%)"
   End Select
Next

'Get CPU Memory Usage Status
' Take a look at the script located here: http://www.vbsedit.com/scripts/Hardware/monitor/scr_374.asp

'Output to text
Set objOutFile = objFSO.OpenTextFile("C:\Server_hdd_cpu_mem.csv", 8, True)
objOutFile.WriteLine "Time,Computer Name,PercentProcessorTime,DriveSpace"
objOutFile.WriteLine strLineTime & "," & oWshSysEnv("COMPUTERNAME") & "," & strLineProcessorTime & "," & strLineDriveSpace
Wscript.Echo "DONE"
Wscript.Quit


(in reply to jeffablang)
Post #: 2
RE: Help me with my VBScript to monitor my computers ha... - 6/13/2008 6:52:22 PM   
rbennett806


Posts: 786
Score: 13
Joined: 6/14/2006
Status: offline
And here's a chunk of VBScript code you can use to pull other data and dump it into an HTML file. I had it sitting at hand so I thought I'd toss it up here for you or anyone else that runs across this post...

'DISCLAIMER: This script is provided "as is" with all faults. The author cannot be held liable for any indirect, special, incidental, consequential, or exemplary damages arising out of or in any way relating to the use of this script, including without limitation damages for loss of goodwill, work stoppage, lost profits, loss of data, and computer failure or malfunction. You bear the entire risk as to the quality and performance of this script.

'~$~----------------------------------------~$~
Option Explicit
const HKEY_CLASSES_ROOT = &H80000000
const HKEY_CURRENT_USER = &H80000001
const HKEY_LOCAL_MACHINE = &H80000002
const HKEY_USERS = &H80000003

Dim objWshShell, objFSO, objNetwork, objWMI, WshEnv, RegExp
Dim strAllUsersDesktopPath, strUserProfilesMainFolder, strCurrentUserDesktop
Dim OutputFile, strMessage, intStartProcess, strInstalledSoftware
Dim strModelNumber, strManufacturer, strSerialNumber, strBIOSversion, strDiskDrive, strVideoController, strScreenResolution, strMonitor, strSoundDevice, strNICinfo, strNICinfo1, strNICinfo2, strNICinfo3

Set objWshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = Wscript.CreateObject("WScript.Network")
Set objWMI = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set WshEnv = objWshShell.Environment("PROCESS")
Set RegExp = new RegExp
RegExp.IgnoreCase = true

' Attempts to obtain the Desktop path for all users.
strAllUsersDesktopPath = objWshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Common Desktop")

' Attempts to configure Windows XP paths.
strUserProfilesMainFolder = Mid(strAllUsersDesktopPath,1,InStr(strAllUsersDesktopPath, "\All Users"))
strCurrentUserDesktop = strUserProfilesMainFolder & objNetwork.UserName & "\Desktop"

If strUserProfilesMainFolder = "" Then
   ' Attempts to configure Windows Vista paths.
   strUserProfilesMainFolder = Mid(strAllUsersDesktopPath,1,InStr(strAllUsersDesktopPath, "\Public"))
   strCurrentUserDesktop = strUserProfilesMainFolder & objNetwork.UserName & "\Desktop"
End If

strMessage = "This script process will attempt to perform a basic inventory of this machine, outputting this information to a .HTM file located on the desktop." + (Chr(13)& Chr(13)& Chr(13)) + "Do you wish to inventory this machine now?"

intStartProcess=objWshShell.Popup(strMessage,, "WORKSTATION INVENTORY SCRIPT...", 4 + 32)

If intStartProcess = 7 Then
   'Clicked the NO button.
   Wscript.Quit
End If

If objFSO.FileExists(strCurrentUserDesktop & "\" & objNetwork.ComputerName & " Inventory.htm") Then
   objFSO.DeleteFile(strCurrentUserDesktop & "\" & objNetwork.ComputerName & " Inventory.htm"), True
End If

set OutputFile = objFSO.OpenTextFile(strCurrentUserDesktop & "\" & objNetwork.ComputerName & " Inventory.htm", 8, True, True)

GetSystemInfo
GetSerialNumber
GetDiskDriveInfo
GetNetworkAdapterInfo
GetAudioInfo
GetVideoControllerInfo
GetScreenResolution
GetMonitorInfo
GetInstalledSoftwareInfo

OutputFile.writeline("<font color=#800000>The following inventory information may be used for advanced troubleshooting purposes during operating system deployment.<br><br><br><font color=#800000>BASIC SYSTEM INFORMATION<table border=1><thead>" & _
"<td bgcolor=#C0C0C0><font color=#800000><strong>Machine Model</strong></td>" & _
"<td bgcolor=#C0C0C0><font color=#800000><strong>Machine Manufacturer</strong></td>" & _
"<td bgcolor=#C0C0C0><font color=#800000><strong>Machine Serial Number</strong></td>" & _
"<td bgcolor=#C0C0C0><font color=#800000><strong>BIOS Version</strong></td>" & _
"<td bgcolor=#C0C0C0><font color=#800000><strong>Current Screen Resolution</strong></td><tr>" & _
"<td>" & strModelNumber & "</td><td>" & strManufacturer & "</td><td>" & strSerialNumber & "</td><td>" & strBIOSversion & "</td><td>" & strScreenResolution & "</td></tr></table><br>" & _
"<font color=#CC6600>PHYSICAL DISK INFORMATION<table border=1><thead>" & _
"<td bgcolor=#C0C0C0><font color=#CC6600><strong>Model</strong></td>" & _
"<td bgcolor=#C0C0C0><font color=#CC6600><strong>Size</strong></td>" & _
"<td bgcolor=#C0C0C0><font color=#CC6600><strong>Partitions</strong></td></thead><tr>" & _
"<td>" & strDiskDrive & "</td></tr></table><br>" & _
"<font color=#008000>NETWORK ADAPTER INFORMATION<table border=1><thead>" & _
"<td bgcolor=#C0C0C0><font color=#008000><strong>MAC Address</strong></td>" & _
"<td bgcolor=#C0C0C0><font color=#008000><strong>Adapter Type</strong></td>" & _
"<td bgcolor=#C0C0C0><font color=#008000><strong>Manufacturer</strong></td>" & _
"<td bgcolor=#C0C0C0><font color=#008000><strong>Description</strong></td>" & _
"<td bgcolor=#C0C0C0><font color=#008000><strong>Network Connection ID</strong></td></thead><tr>" & _
"<td>" & strNICinfo & "</td></tr></table><br>" & _
"<font color=#0000FF>VIDEO CONTROLLER INFORMATION<table border=1><thead>" & _
"<td bgcolor=#C0C0C0><font color=#0000FF><strong>Description</strong></td>" & _
"<td bgcolor=#C0C0C0><font color=#0000FF><strong>Video RAM</strong></td></thead><tr>" & _
"<td>" & strVideoController & "</td></tr></table><br>" & _
"<font color=#800080>MONITOR INFORMATION<table border=1><thead>" & _
"<td bgcolor=#C0C0C0><font color=#800080><strong>Manufacturer</strong></td>" & _
"<td bgcolor=#C0C0C0><font color=#800080><strong>Type</strong></td>" & _
"<td bgcolor=#C0C0C0><font color=#800080><strong>Description</strong></td></thead><tr>" & _
"<td>" & strMonitor & "</td></tr></table><br>" & _
"<font color=#008080>SOUND DEVICE INFORMATION<table border=1><thead>" & _
"<td bgcolor=#C0C0C0><font color=#008080><strong>Manufacturer</strong></td>" & _
"<td bgcolor=#C0C0C0><font color=#008080><strong>Description</strong></td></thead><tr>" & _
"<td>" & strSoundDevice & "</td></tr></table><br>" & _
"<font color=#333300>INSTALLED SOFTWARE INFORMATION<table border=1><thead><td bgcolor=#C0C0C0><font color=#333300><strong>DisplayName</strong></td><td bgcolor=#C0C0C0><font color=#333300><strong>DisplayVersion</strong></thead><tr><td>" & strInstalledSoftware & "</table><br>")

OutputFile.Close
Wscript.echo "Done inventorying this machine."
Wscript.Quit



' ~$~----------------------------------------~$~
'            FUNCTIONS & SUBROUTINES
' ~$~----------------------------------------~$~
Sub GetSystemInfo
' Obtains the Model Number and Manufacturer information.
Dim colWin32_ComputerSystem, objItem

Set colWin32_ComputerSystem = objWMI.ExecQuery("select * from Win32_ComputerSystem")
For Each objItem In colWin32_ComputerSystem
   strModelNumber = Trim(objItem.Model)
   strManufacturer = Trim(objItem.Manufacturer)
Next

If Mid(strModelNumber, 2) = "" Then
   strModelNumber = ""   
End If

' Checks for an exception where the Model Number is a quotation mark.
If strModelNumber = """" Then
   strModelNumber = ""
End If

' Checks for some exceptions where a Gateway motherboard is noted as the Model Number.
If strModelNumber = "FEDORA" Then
   strModelNumber = ""
End If

If strModelNumber = "MIDWAY" Then
   strModelNumber = ""
End If

If strModelNumber = "LEXINGTON" Then
   strModelNumber = ""
End If

If strModelNumber = "MP44BX" Then
   strModelNumber = ""
End If
End Sub

' ~$~----------------------------------------~$~
Sub GetSerialNumber
' Obtains the Serial Number information.
Dim colWin32_BIOS, objBIOSitem

Set colWin32_BIOS = objWMI.ExecQuery("select * from Win32_BIOS")
For Each objBIOSitem In colWin32_BIOS
   strSerialNumber = Trim(objBIOSitem.SerialNumber)
   strBIOSversion = objBIOSitem.SMBIOSBIOSversion
Next

If strSerialNumber = "ÿÿÿÿÿ" Then
   strSerialNumber = ""
End If

If strSerialNumber = "DELL" Then
   strSerialNumber = ""
End If

If strSerialNumber = "00000000" Then
   strSerialNumber = ""
End If
End Sub

' ~$~----------------------------------------~$~
Sub GetDiskDriveInfo
' Obtains the physical disk drive information.
Dim colWin32_DiskDrive, objDiskDriveItem

Set colWin32_DiskDrive = objWMI.ExecQuery("select * from Win32_DiskDrive")
strDiskDrive = ""
For Each objDiskDriveItem In colWin32_DiskDrive
   If strDiskDrive = "" Then
       strDiskDrive = objDiskDriveItem.Model & "</td><td>" & Int(objDiskDriveItem.Size /(1073741824)) & " GBs </td><td>" & objDiskDriveItem.Partitions
   Else
       strDiskDrive = strDiskDrive & "</td></tr><tr><td>" & objDiskDriveItem.Model & "</td><td>" & Int(objDiskDriveItem.Size /(1073741824)) & " GBs </td><td>" & objDiskDriveItem.Partitions
   End If
Next
End Sub

' ~$~----------------------------------------~$~
Sub GetNetworkAdapterInfo
' Obtains the NIC information (only supports 2 network adapter cards).
Dim colWin32_NetworkAdapter, objNICitem

Set colWin32_NetworkAdapter = objWMI.ExecQuery("select * from Win32_NetworkAdapter")
strNICinfo = ""
For Each objNICitem In colWin32_NetworkAdapter
   If Not objNICitem.MACaddress = "" Then
       If strNICinfo = "" Then
           strNICinfo = objNICitem.MACaddress & "</td><td>" & objNICitem.AdapterType & "</td><td>" & objNICitem.Manufacturer & "</td><td>" & objNICitem.Description & "</td><td>" & objNICitem.NetConnectionID & "</td></tr><tr><td>"
       Else
           strNICinfo = strNICinfo & "</td></tr><tr><td>" & objNICitem.MACaddress & "</td><td>" & objNICitem.AdapterType & "</td><td>" & objNICitem.Manufacturer & "</td><td>" & objNICitem.Description & "</td><td>" & objNICitem.NetConnectionID & "</td></tr><tr><td>"
       End If
   End If
Next
End Sub

' ~$~----------------------------------------~$~
Sub GetAudioInfo
' Obtains the sound device information.
Dim colWin32_SoundDevice, objSoundDeviceItem

Set colWin32_SoundDevice = objWMI.ExecQuery("select * from Win32_SoundDevice")
strSoundDevice = ""
For Each objSoundDeviceItem In colWin32_SoundDevice
   If strSoundDevice = "" Then
       strSoundDevice = Trim(objSoundDeviceItem.Manufacturer) & "</td><td>" & Trim(objSoundDeviceItem.Description)
   Else
       strSoundDevice = strSoundDevice & "</td></tr><tr><td>" & Trim(objSoundDeviceItem.Manufacturer) & "</td><td>" & Trim(objSoundDeviceItem.Description)
   End If
Next
End Sub

' ~$~----------------------------------------~$~
Sub GetVideoControllerInfo
' Obtains the video controller information.
Dim colWin32_VideoController, objVideoControllerItem

Set colWin32_VideoController = objWMI.ExecQuery("select * from Win32_VideoController")
strVideoController = ""
For Each objVideoControllerItem In colWin32_VideoController
   If Not "Microsoft SMS Mirror Driver" = objVideoControllerItem.Name Then
       If strVideoController = "" Then
           strVideoController = Trim(objVideoControllerItem.Name) & "</td><td>" & objVideoControllerItem.AdapterRAM / 1048576 & " MBs"
       Else
           RegExp.pattern = Trim(objVideoControllerItem.Name)
           If (RegExp.test (strVideoController) = TRUE) Then
               strVideoController = strVideoController & "</td></tr><tr><td>" & Trim(objVideoControllerItem.Name) & "</td><td>" & objVideoControllerItem.AdapterRAM / 1048576 & " MBs"
           End If
       End If
   End If
Next
End Sub

' ~$~----------------------------------------~$~
Sub GetScreenResolution
' Obtains the screen resolution information.
Dim colWin32_DisplayConfiguration, objDisplayConfigurationItem

Set colWin32_DisplayConfiguration = GetObject( "winmgmts://./root/cimv2" ).ExecQuery( "Select * from Win32_DisplayConfiguration", , 48 )
For Each objDisplayConfigurationItem in colWin32_DisplayConfiguration
   strScreenResolution = objDisplayConfigurationItem.PelsWidth & " x " & objDisplayConfigurationItem.PelsHeight
Next
End Sub

' ~$~----------------------------------------~$~
Sub GetMonitorInfo
' Obtains the monitor information.
Dim colWin32_DesktopMonitor, objMonitorItem

Set colWin32_DesktopMonitor = objWMI.ExecQuery("select * from Win32_DesktopMonitor")
strMonitor = ""
For Each objMonitorItem In colWin32_DesktopMonitor
   If strMonitor = "" Then
       strMonitor = objMonitorItem.MonitorManufacturer & "</td><td>" & objMonitorItem.MonitorType & "</td><td>" & objMonitorItem.Description
   Else
       strMonitor = strMonitor & "</td></tr><tr><td>" & objMonitorItem.MonitorManufacturer & "</td><td>" & objMonitorItem.MonitorType & "</td><td>" & objMonitorItem.Description
   End If
Next
End Sub

' ~$~----------------------------------------~$~
Sub GetInstalledSoftwareInfo
' Attempts to obtain the information for the applications registered within the Add/Remove Programs applet.
Dim objReg, strKeyPath, intRC, subkey, arrSubKeys, strValue

strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")

strInstalledSoftware = "<td>"

intRC = objReg.EnumKey(HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys)

For Each subkey In arrSubKeys
   intRC = objReg.GetStringValue(HKEY_LOCAL_MACHINE, strKeyPath & subkey, "DisplayName", strValue)
   If intRC <> 0 Then
       objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & subkey, "QuietDisplayName", strValue
   End If
   If strValue <> "" Then
       If Len(strValue)>3 Then
           RegExp.Pattern = "Hotfix "
           If Not (RegExp.test (strValue) = TRUE) Then
               RegExp.Pattern = "Security Update for "
               If Not (RegExp.test (strValue) = TRUE) Then
                   RegExp.Pattern = "Update for Windows"
                   If Not (RegExp.test (strValue) = TRUE) Then
                       strInstalledSoftware = strInstalledSoftware & "</td></tr><tr><td>" & strValue
                       intRC = objReg.GetStringValue(HKEY_LOCAL_MACHINE, strKeyPath & subkey, "DisplayVersion", strValue)
                       If strValue <> "" Then
                           strInstalledSoftware = strInstalledSoftware & "</td><td>" & strValue & "</td></tr><tr><td>"
                       Else
                           strInstalledSoftware = strInstalledSoftware
                       End If
                   End If
               End If
           End If
       End If
   End If
Next
End Sub

* It may have some extra variables and/or code as I culled out some extra non-related info...

(in reply to rbennett806)
Post #: 3
RE: Help me with my VBScript to monitor my computers ha... - 6/16/2008 12:01:18 PM   
kdsrazor


Posts: 235
Score: 10
Joined: 1/6/2006
Status: offline
An entirely different approach would be to use Perfmon and MRTG.  You wouldn't have to do any scripting.

_____________________________

Ken Aldrich
Senior Support Engineer
Visual Click Software
512-231-9990 x 2
supportw@visualclick.com

(in reply to rbennett806)
Post #: 4
RE: Help me with my VBScript to monitor my computers ha... - 6/19/2008 2:23:59 AM   
jeffablang

 

Posts: 4
Score: 0
Joined: 6/13/2008
Status: offline
I really appreciate your help. Now all I need is to find out how can I get the result of the MEMORY STATUS. I tried using the same code using the CPU but the result did not appear again I think there is something wrong. It did not show any error when I try to execute it.

Option
Explicit

Dim
oWsh, oWshSysEnv, objFSO, objWMIService
Dim
oDrives, oDrive, objOutFile, colItems, objItem
Dim
strLineTime, strLineProcessorTime, strLineDriveSpace, strLinePercentCommittedBytesInUse

Set
oWsh = WScript.CreateObject("WScript.Shell")
Set
oWshSysEnv = oWsh.Environment("PROCESS")
Set
objFSO = CreateObject("Scripting.FileSystemObject")
Set
objWMIService = GetObject("winmgmts:\\.\root\CIMV2")

strLineTime =
Date() & Space(2) & Time()

'Gets PROCESSOR Usage

Set
colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name = '_Total'")
For
Each objItem In colItems
strLineProcessorTime = strLineProcessorTime &
" " & objItem.PercentProcessorTime(" % ")
Next


'Gets CPU MEMORY Usage

Set
colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_Memory WHERE Name = '_Total'")
For
Each objItem In colItems
strLinePercentCommittedBytesInUse = strLinePercentCommittedBytesInUse &
" " & objItem.PercentCommittedBytesInUse(" % ")
Next


'Gets FREE SPACE Report

Set
oDrives = objFSO.Drives
For
Each oDrive In oDrives
Select Case oDrive.DriveType
Case 2 'Fixed Drives
strLineDriveSpace = strLineDriveSpace &
" " & oDrive.DriveLetter & "\: " & Round(oDrive.FreeSpace / (1024 * 1024)) & "MB free (" & Round(100 * (oDrive.FreeSpace / oDrive.TotalSize), 2) & " %) "
End Select
Next


'Output to text

Set
objOutFile = objFSO.OpenTextFile("C:\hdd_cpu_ram_MONv1.csv", 8, True)
objOutFile.WriteLine
"Time,Computer Name,Processor Usage (%),Memory Usage (%),Drive Free Space"
objOutFile.WriteLine strLineTime &
"," & oWshSysEnv("COMPUTERNAME") & "," & strLineProcessorTime & "," & strLinePercentCommittedBytesInUse & "," & strLineDriveSpace

WScript.Echo "DONE"

WScript
.Quit

Jeff

(in reply to kdsrazor)
Post #: 5
RE: Help me with my VBScript to monitor my computers ha... - 6/19/2008 4:44:42 AM   
jeffablang

 

Posts: 4
Score: 0
Joined: 6/13/2008
Status: offline
rbennett806 & other members

I already made this working.... I'm glad to be  amember of this forum, I really appreciate all your help.

Thank you again.

JeffAblang


(in reply to jeffablang)
Post #: 6
Help me with my VBScript to monitor my computers harddi... - 8/6/2008 9:30:19 PM   
jeffablang

 

Posts: 4
Score: 0
Joined: 6/13/2008
Status: offline
Hi everyone I already tried using this script to monitor my servers but I have a little problem which I think I could use a little help from you

as you can see in the "Get Processor" part I noticed that the result is only incresing in value... i'm afraid that this is not really the CPU usage.

sample output:

0
0.1
0.2
0.6
0.7
0.8
0.9
1
1.5


================================================
Option Explicit

Dim oWsh, oWshSysEnv, objFSO, objWMIService
Dim oDrives, oDrive, objOutFile, colItems, objItem
Dim strLineDate, strLineTime, strLineProcessorTime, strLineDriveSpace, strLinePercentCommittedBytesInUse

Set oWsh = WScript.CreateObject("WScript.Shell")
Set oWshSysEnv = oWsh.Environment("PROCESS")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")

strLineDate = Date()
strLineTime = Time()

'Gets PROCESSOR Usage
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name = '_Total'")
For Each objItem In colItems      
   strLineProcessorTime = strLineProcessorTime & " " & objItem.PercentProcessorTime
Next

'Gets MEMORY Usage
Set colItems = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_PerfFormattedData_PerfOS_Memory ")
For Each objItem In colItems      
   strLinePercentCommittedBytesInUse = strLinePercentCommittedBytesInUse & " " & objItem.PercentCommittedBytesInUse
Next

'Gets FREE SPACE Report
Set oDrives = objFSO.Drives
For Each oDrive In oDrives
   Select Case oDrive.DriveType
       Case 2 'Fixed Drives            
           strLineDriveSpace = strLineDriveSpace & " " & oDrive.DriveLetter & "\: " & Round(oDrive.FreeSpace / (1024 * 1024) / 1024,2) & "  Gb free (" & Round(100 * (oDrive.FreeSpace / oDrive.TotalSize), 1) & " %) "
   End Select
Next


'Output to text
Set objOutFile = objFSO.OpenTextFile("C:\MONitoring.csv", 8, True)
'objOutFile.WriteLine "Date,Time,Computer Name,Processor Usage (%),Memory Usage (%),Drive Free Space"'
objOutFile.WriteLine strLineDate & "," & strLineTime & "," & oWshSysEnv("COMPUTERNAME") & "," & strLineProcessorTime & "," &
strLinePercentCommittedBytesInUse & "," & strLineDriveSpace

'WScript.Echo "DONE"
WScript.Quit

(in reply to jeffablang)
Post #: 7
Page:   [1]
All Forums >> [Scripting Technologies] >> VB Script >> Help me with my VBScript to monitor my computers harddisk, cpu and memory Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts



  
Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

0.277