VBScript: a method for gathering hardware information from machines on a given network

Binaries

‘Script created by Mike Nesbit – 4-28-2010

‘Here is a script that will provide valuable inventory information on computers that we
‘choose on our domain.  Utilizing the registry and various WMI services, we can pull the
‘installed software, video, bios, ram, processor, and hard drive information.
‘This script will require a command line argument -name of machine- and will output
‘the information to a text file named after the computer we choose.

On Error Resume Next

Dim strComputer ‘ the variable that will be used to idenfity the machien we will be gathering information from
Dim oReg ‘ the variable that will be used to connect and gather information from the registry about instaleld software
Dim colItems ‘ the variable that will be used to hold a lot of collections qeuried from various Win_32 Services
Dim objItem  ‘ objItem will be used to hold the different items that we request to output
Dim objWMIService ‘ this will hold the connection to the various WMI services that we will be using
Dim colSettings ‘ is used as a variable to hold a collection of information that is queried from various services
Dim objRAM ‘ my variable that will hold the information pertaining to the available RAM
Dim objProcessor ‘ my variable that will hold each piece of info I request about the processor
Dim objBIOS ‘ my variable that will be used to hold each piece of info I request from the Bios
Dim FSO  ‘ the variable that will be used to create the object which is a text file
Dim text   ‘ my variable to be used to be used to create the text file
Dim subkey
Dim arrSubkeys

strComputer = WScript.Arguments(0)   ‘ using strComputer to create a command line argument – we want to be able to choose the computer
If WScript.Arguments.Count = 0 Then ‘ use the if then command – if the argument is 0 then
WScript.Echo(“You must enter a computer name”) ‘ we will have it echo that we must enter a computer name
Else ‘ if we do enter a name – then the script does not = 0 and the script moves to the else command which moves the script forward
Const HKEY_LOCAL_MACHINE = &H80000002  ‘ here is where a constant is used to access the locan machine registry
Const UnInstPath = “SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\” ‘a constant that points to exactly where we want to search for the registry software – in this case we are looking for software that can be uninstalled
Set oReg=GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate}!\\” & strComputer & “\root\default:StdRegProv”) ‘the rest of the line is set to grab the information from the registry – I use strcomputer here as well so it will grab from the machine we choose instead of the local machine

write = strComputer & ” Computer Inventory” & vbCrLf & “——————————————” & vbCrLf & vbCrLf ‘ the report command here is used to write data to the text file – here we are using strcomptuer so that it writes the name of the computer we are inventoring along with the text “computer inventory”

Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2″)  ‘ objWMIService is set to equal the getobject command in winmgmts
Set colSettings = objWMIService.ExecQuery(“Select * from Win32_OperatingSystem”,,48) ‘colItems is equaled to the objWMISergice query information from the Win32_OperatingSystem service
write = write & vbCrLf & “——————————————” & vbCrLf     ‘ report is again used to create the lines (makes the text look more organized)
write = write & “Operating System” & vbCrLf & “——————————————” & vbCrLf & vbCrLf  ‘ again we use report to write out Operating System in the text

For Each objItem in colSettings  ‘ the for each command here is set to give us the information from the colItems that we queried above.  For each item that we want in our collection – it will be displayed below by what we want from it
write = write &  “Caption: ” & objItem.Caption & vbCrLf
write = write &  “Description: ” & objItem.Description & vbCrLf
write = write &  “EncryptionLevel: ” & objItem.EncryptionLevel & vbCrLf
write = write &  “InstallDate: ” & objItem.InstallDate & vbCrLf
write = write &  “Manufacturer: ” & objItem.Manufacturer & vbCrLf
write = write &  “MaxNumberOfProcesses: ” & objItem.MaxNumberOfProcesses & vbCrLf
write = write &  “Name: ” & objItem.Name & vbCrLf
write = write &  “Organization: ” & objItem.Organization & vbCrLf
write = write &  “OSProductSuite: ” & objItem.OSProductSuite & vbCrLf
write = write &  “RegisteredUser: ” & objItem.RegisteredUser & vbCrLf
write = write &  “SerialNumber: ” & objItem.SerialNumber & vbCrLf
write = write &  “ServicePackMajorVersion: ” & objItem.ServicePackMajorVersion
write = write &  “ServicePackMinorVersion: ” & objItem.ServicePackMinorVersion & vbCrLf
write = write &  “Version: ” & objItem.Version & vbCrLf
write = write &  “WindowsDirectory: ” & objItem.WindowsDirectory & vbCrLf
Next

Set colSettings = objWMIService.ExecQuery(“Select * from Win32_ComputerSystem”) ‘ and we use the select statement for the Win32_ComputerSystem
write = write & vbCrLf & “——————————————” & vbCrLf
write = write & “RAM Information” & vbCrLf & “——————————————” & vbCrLf & vbCrLf  ‘ again we are using report to write text to the file

For Each objRAM in colSettings   ‘ for each command is used here to tell us that for each item found in the colsettings we queried above
write = write & objRAM.TotalPhysicalMemory /1024\1024+1 & “MB Total memory” & vbcrlf  ‘ this line is to report the total memory of ram that is available on the machine.
Next

Set colSettings = objWMIService.ExecQuery(“Select * from Win32_Processor” , , 48 )  ‘ and it will query information from the Win32_Processor service
write = write & vbCrLf & “——————————————” & vbCrLf
write = write & “Processor Information” & vbCrLf & “——————————————” & vbCrLf & vbCrLf ‘ again we are writing out the lines to organize the output text and will also write Processor

For Each objProcessor in colSettings  ‘ for each command is used again to tell us that for each item that is found from the colsettings query above – it will display what we want below which is what the objProcessor is used for – to hold those items
write = write & “Name: ” & objProcessor.Name & vbCrLf
write = write & “Manufacturer: ” & objProcessor.Manufacturer & vbCrLf
write = write & “Description: ” & objProcessor.Description & vbCrLf
write = write & “Current Clock Speed: ” & objProcessor.CurrentClockSpeed & ” MHz” & vbCrLf & vbCrLf
Next

Set colSettings = objWMIService.ExecQuery(“Select * from Win32_BIOS” , , 48)             ‘ here we are setting the colsettings variable to equal the objWMIService query in which case we will be gathering information from the Win32_BIOS service
write = write & vbCrLf & “——————————————” & vbCrLf
write = write & “BIOS Information” & vbCrLf & “——————————————” & vbCrLf & vbCrLf  ‘ again we write out the lines and the ‘BIOS Information’ to the text file

For each objBIOS in colSettings  ‘ for each command is used here to tell us that for each item that is found from the colsettings query above – it will display what we want below which is what the objBIOS variable is used for
write = write & “Build Number: ” & objBIOS.BuildNumber & vbCrLf
write = write & “Current Language: ” & objBIOS.CurrentLanguage & vbCrLf
write = write & “Installable Languages: ” & objBIOS.InstallableLanguages  & vbCrLf
write = write & “Manufacturer: ” & objBIOS.Manufacturer & vbCrLf
write = write & “Name: ” & objBIOS.Name & vbCrLf
write = write & “Primary BIOS: ” & objBIOS.PrimaryBIOS & vbCrLf
write = write & “Release Date: ” & objBIOS.ReleaseDate & vbCrLf
write = write & “Serial Number: ” & objBIOS.SerialNumber & vbCrLf
write = write & “SMBIOS Version: ” & objBIOS.SMBIOSBIOSVersion & vbCrLf
write = write & “SMBIOS Major Version: ” & objBIOS.SMBIOSMajorVersion & vbCrLf
write = write & “SMBIOS Minor Version: ” & objBIOS.SMBIOSMinorVersion & vbCrLf
write = write & “SMBIOS Present: ” & objBIOS.SMBIOSPresent & vbCrLf
write = write & “Status: ” & objBIOS.Status & vbCrLf
write = write & “Version: ” & objBIOS.Version & vbCrLf

Next

write = write & vbCrLf & “——————————————” & vbCrLf
write = write & “Video/Display Information” & vbCrLf & “——————————————” & vbCrLf & vbCrLf  ‘ again writing information to the text file
Set colSettings = objWMIService.ExecQuery( “Select * from Win32_VideoController”, , 48 )  ‘ colsettings is again equaled to the objWMIService in which case we will be gathering information from the Win32_VideoController service

For Each objItem in colSettings  ‘ for each command again to tell us that for each item that is found in our above colsettings query – it will display what we want below and that is what objItem is used for – to hold that information
write = write & ” Name: ” & objItem.Name & vbCrLf
write = write & ” Description: ” & objItem.Description & vbCrLf
write = write & ” Video Processor: ” & objItem.VideoProcessor & vbCrLf
write = write & ” Adapter RAM: ” & Int( ( objItem.AdapterRAM + 524288 ) / 1048576 ) & ” MB” & vbCrLf
write = write & ” Video Mode Description:  ” & objItem.VideoModeDescription & vbCrLf & vbCrLf
Next

write = write & vbCrLf & “——————————————” & vbCrLf
write = write & “Hard Drive Information” & vbCrLf & “——————————————” & vbCrLf & vbCrLf  ‘ writing data to the text file
Set colSettings = objWMIService.ExecQuery( “Select * from Win32_DiskDrive”, , 48 ) ‘ colsettings is set to = the objWMIService query again – this time it will query from Win32_DiskDrive service

For Each objItem in colSettings  ‘ for each command that will tell us that for each item found in the above colsettings query – it will ouput the information we request below
write = write & ” Manufacturer: ” & objItem.Manufacturer & vbCrLf
write = write & ” Model: ” & objItem.Model & vbCrLf
write = write & ” Size: ” & Int( ( objItem.Size + 536870912 ) / 1073741824 ) & ” GB” & vbCrLf & vbCrLf

Next

oReg.EnumKey HKEY_LOCAL_MACHINE, UnInstPath, arrSubKeys    ‘ here oReg.EnumKey is again in conjunction with the registry path of our choice
write = write & vbCrLf & “——————————————” & vbCrLf
write = write & “Installed Software” & vbCrLf & “——————————————” & vbCrLf & vbCrLf  ‘ writing the reports to the text file

For Each subkey In arrSubKeys  ‘ we set up the for each command one last time to tell us that for iten found in query from the arrSubkeys variable that we will output what we need below
If Left (subkey, 1) <> “{” Then
write = write & subkey & vbCrLf
End If
Next

Set fso = CreateObject(“Scripting.FileSystemObject”)   ‘ here is where fso is set to the createobject command – this is where it understands that it must create a file system object – such as a text file
Set text = fso.CreateTextFile (strComputer & “.txt”, ForWriting) ‘ the variable text is set to equal the fso variable that we defined above – here it is used to create a text file – the text file will be named whatever the computer we are searching for is named – this is why we use strcomputer variable here – we could name it anything
text.write write     ‘ this command tells it to write the reports that were gathered throughout the entire script – yes we could have named it anything
text.close      ‘ here is where we tell the script to close the text file when no more writing is needed
End If
Wscript.Echo “I have finished retrieving the information”   ‘ and of course we end it with a Wscript.Echo command which will state that it is finished when the script is completed

Comments are closed.