(view source code of hardware.vbs as plain text)
Option Explicit
Dim intHDUs, intMem, intMod, intCPUs
Dim colItems, objItem, objWMIService
Dim strComputer, strMsg
' Check command line parameters
With WScript.Arguments
If .Named.Count > 0 Then Syntax
Select Case .Unnamed.Count
Case 0
' Default if none specified is local computer (".")
strComputer = "."
Case 1
' Command line parameter can either be a computer
' name or "/?" to request online help
strComputer = UCase( .Unnamed(0) )
if InStr( strComputer, "?" ) > 0 Then Syntax
Case Else
' Maximum is 1 command line parameter
Syntax
End Select
End With
' Enable custom error handling
On Error Resume Next
' Connect to the computer
Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
' Display error number and description if applicable
If Err Then ShowError
' Get the real computer name
Set colItems = objWMIService.ExecQuery( "Select * from Win32_ComputerSystem" )
' Display error number and description if applicable
If Err Then ShowError
For Each objItem in colItems
strComputer = objItem.Name
Next
' Header line for screen output
strMsg = vbCrLf & "Hardware summary for " & strComputer & ":" & vbCrLf & vbCrLf
' Query processor properties
Set colItems = objWMIService.ExecQuery( "Select * from Win32_Processor" )
' Display error number and description if applicable
If Err Then ShowError
' Prepare display of results
intCPUs = 0
For Each objItem in colItems
intCPUs = intCPUs + 1
strMsg = strMsg & "Processor"
If colItems.Count > 1 Then
strMsg = strMsg & " " & intCPUs
End If
strMsg = strMsg & vbCrLf & " Name : " _
& Trim( objItem.Name ) & vbCrLf _
& " Manufacturer : " _
& objItem.Manufacturer & vbCrLf _
& " Description : " _
& objItem.Description & vbCrLf _
& " Current Clock Speed : " _
& objItem.CurrentClockSpeed & " MHz" _
& vbCrLf & vbCrLf
Next
' Query memory properties
Set colItems = objWMIService.ExecQuery( "Select * from Win32_MemoryDevice" )
' Display error number and description if applicable
If Err Then ShowError
intMem = 0
intMod = 0
For Each objItem in colItems
intMem = intMem + objItem.EndingAddress - objItem.StartingAddress
intMod = intMod + 1
Next
strMsg = strMsg & "Memory" _
& vbCrLf _
& " Memory Modules : " & intMod _
& vbCrLf _
& " Total Physical Memory : " & Int( ( intMem + 1023 ) / 1024 ) & " MB" _
& vbCrLf & vbCrLf
' Query harddisk properties
Set colItems = objWMIService.ExecQuery( "Select * from Win32_DiskDrive where Size>0" )
' Display error number and description if applicable
If Err Then ShowError
' Prepare display of results
intHDUs = 0
For Each objItem in colItems
intHDUs = intHDUs + 1
strMsg = strMsg & "Harddisk"
If colItems.Count > 1 Then
strMsg = strMsg & " " & intHDUs
End If
strMsg = strMsg & vbCrLf & " Manufacturer : " _
& objItem.Manufacturer & vbCrLf _
& " Model : " _
& objItem.Model & vbCrLf _
& " Size : " _
& Int( ( objItem.Size + 536870912 ) / 1073741824 ) _
& " GB" & vbCrLf & vbCrLf
Next
' Query video adapter properties
Set colItems = objWMIService.ExecQuery( "Select * from Win32_VideoController" )
' Display error number and description if applicable
If Err Then ShowError
' Prepare display of results
For Each objItem in colItems
strMsg = strMsg & "Video" & vbCrLf _
& " Name : " _
& objItem.Name & vbCrLf _
& " Description : " _
& objItem.Description & vbCrLf _
& " Video Processor : " _
& objItem.VideoProcessor & vbCrLf _
& " Adapter RAM : " _
& Int( ( objItem.AdapterRAM + 1048575 ) / 1048576 ) _
& " MB" & vbCrLf _
& " Video Mode Description : " _
& objItem.VideoModeDescription & vbCrLf & vbCrLf
Next
' Display results
WScript.Echo strMsg
'Done
WScript.Quit(0)
Sub ShowError()
strMsg = vbCrLf & "Error # " & Err.Number & vbCrLf & _
Err.Description & vbCrLf & vbCrLf
Syntax
End Sub
Sub Syntax()
strMsg = strMsg _
& vbCrLf _
& "Hardware.vbs, Version 2.00" _
& vbCrLf _
& "Display basic hardware summary for any WMI enabled computer on the network" _
& vbCrLf & vbCrLf _
& "Usage: CSCRIPT.EXE //NoLogo HARDWARE.VBS [ computer ]" _
& vbCrLf & vbCrLf _
& "Where: ""computer"" is an optional remote computer name" _
& vbCrLf _
& " (default is the local computer name)" _
& vbCrLf & vbCrLf _
& "Written by Rob van der Woude" _
& vbCrLf _
& "http://www.robvanderwoude.com"
WScript.Echo strMsg
WScript.Quit(1)
End Sub
page last modified: 2024-04-16; loaded in 0.0065 seconds