|
rbennett806 -> RE: Help me with my VBScript to monitor my computers harddisk, cpu and memory (6/13/2008 6:52:22 PM)
|
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...
|
|
|
|