Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for hardware.vbs

(view source code of hardware.vbs as plain text)

  1. Option Explicit
  2.  
  3. Dim intHDUs, intMem, intMod, intCPUs
  4. Dim colItems, objItem, objWMIService
  5. Dim strComputer, strMsg
  6.  
  7. ' Check command line parameters
  8. With WScript.Arguments
  9. 	If .Named.Count > 0 Then Syntax
  10. 	Select Case .Unnamed.Count
  11. 		Case 0
  12. 			' Default if none specified is local computer (".")
  13. 			strComputer = "."
  14. 		Case 1
  15. 			' Command line parameter can either be a computer
  16. 			' name or "/?" to request online help
  17. 			strComputer = UCase( .Unnamed(0) )
  18. 			if InStr( strComputer, "?" ) > 0 Then Syntax
  19. 		Case Else
  20. 			' Maximum is 1 command line parameter
  21. 			Syntax
  22. 	End Select
  23. End With
  24.  
  25. ' Enable custom error handling
  26. On Error Resume Next
  27.  
  28. ' Connect to the computer
  29. Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
  30. ' Display error number and description if applicable
  31. If Err Then ShowError
  32.  
  33. ' Get the real computer name
  34. Set colItems = objWMIService.ExecQuery( "Select * from Win32_ComputerSystem" )
  35. ' Display error number and description if applicable
  36. If Err Then ShowError
  37. For Each objItem in colItems
  38. 	strComputer = objItem.Name
  39. Next
  40.  
  41. ' Header line for screen output
  42. strMsg = vbCrLf & "Hardware summary for " & strComputer & ":" & vbCrLf & vbCrLf
  43.  
  44. ' Query processor properties
  45. Set colItems = objWMIService.ExecQuery( "Select * from Win32_Processor" )
  46. ' Display error number and description if applicable
  47. If Err Then ShowError
  48. ' Prepare display of results
  49. intCPUs = 0
  50. For Each objItem in colItems
  51. 	intCPUs = intCPUs + 1
  52. 	strMsg = strMsg & "Processor"
  53. 	If colItems.Count > 1 Then
  54. 		strMsg = strMsg & " " & intCPUs
  55. 	End If
  56. 	strMsg = strMsg & vbCrLf & "    Name                    : " _
  57. 	       & Trim( objItem.Name ) & vbCrLf _
  58. 	       & "    Manufacturer            : " _
  59. 	       & objItem.Manufacturer & vbCrLf _
  60. 	       & "    Description             : " _
  61. 	       & objItem.Description & vbCrLf _
  62. 	       & "    Current Clock Speed     : " _
  63. 	       & objItem.CurrentClockSpeed & " MHz" _
  64. 	       & vbCrLf & vbCrLf
  65. Next
  66.  
  67. ' Query memory properties
  68. Set colItems = objWMIService.ExecQuery( "Select * from Win32_MemoryDevice" )
  69. ' Display error number and description if applicable
  70. If Err Then ShowError
  71. intMem = 0
  72. intMod = 0
  73. For Each objItem in colItems
  74. 	intMem = intMem + objItem.EndingAddress - objItem.StartingAddress
  75. 	intMod = intMod + 1
  76. Next
  77. strMsg = strMsg & "Memory" _
  78.        & vbCrLf _
  79.        & "    Memory Modules          : " & intMod _
  80.        & vbCrLf _
  81.        & "    Total Physical Memory   : " & Int( ( intMem + 1023 ) / 1024 ) & " MB" _
  82.        & vbCrLf & vbCrLf
  83.  
  84. ' Query harddisk properties
  85. Set colItems = objWMIService.ExecQuery( "Select * from Win32_DiskDrive where Size>0" )
  86. ' Display error number and description if applicable
  87. If Err Then ShowError
  88. ' Prepare display of results
  89. intHDUs = 0
  90. For Each objItem in colItems
  91. 	intHDUs = intHDUs + 1
  92. 	strMsg = strMsg & "Harddisk"
  93. 	If colItems.Count > 1 Then
  94. 		strMsg = strMsg & " " & intHDUs
  95. 	End If
  96. 	strMsg = strMsg & vbCrLf & "    Manufacturer            : " _
  97. 	       & objItem.Manufacturer & vbCrLf _
  98. 	       & "    Model                   : " _
  99. 	       & objItem.Model & vbCrLf _
  100. 	       & "    Size                    : " _
  101. 	       & Int( ( objItem.Size + 536870912 ) / 1073741824 ) _
  102. 	       & " GB" & vbCrLf & vbCrLf
  103. Next
  104.  
  105. ' Query video adapter properties
  106. Set colItems = objWMIService.ExecQuery( "Select * from Win32_VideoController" )
  107. ' Display error number and description if applicable
  108. If Err Then ShowError
  109. ' Prepare display of results
  110. For Each objItem in colItems
  111. 	strMsg = strMsg & "Video" & vbCrLf _
  112. 	       & "    Name                    : " _
  113. 	       & objItem.Name & vbCrLf _
  114. 	       & "    Description             : " _
  115. 	       & objItem.Description & vbCrLf _
  116. 	       & "    Video Processor         : " _
  117. 	       & objItem.VideoProcessor & vbCrLf _
  118. 	       & "    Adapter RAM             : " _
  119. 	       & Int( ( objItem.AdapterRAM + 1048575 ) / 1048576 ) _
  120. 	       & " MB" & vbCrLf _
  121. 	       & "    Video Mode Description  : " _
  122. 	       & objItem.VideoModeDescription & vbCrLf & vbCrLf
  123. Next
  124.  
  125. ' Display results
  126. WScript.Echo strMsg
  127.  
  128. 'Done
  129. WScript.Quit(0)
  130.  
  131.  
  132. Sub ShowError()
  133. 	strMsg = vbCrLf & "Error # " & Err.Number & vbCrLf & _
  134. 	         Err.Description & vbCrLf & vbCrLf
  135. 	Syntax
  136. End Sub
  137.  
  138.  
  139. Sub Syntax()
  140. 	strMsg = strMsg _
  141. 	       & vbCrLf _
  142. 	       & "Hardware.vbs,  Version 2.00" _
  143. 	       & vbCrLf _
  144. 	       & "Display basic hardware summary for any WMI enabled computer on the network" _
  145. 	       & vbCrLf & vbCrLf _
  146. 	       & "Usage:  CSCRIPT.EXE  //NoLogo  HARDWARE.VBS  [ computer ]" _
  147. 	       & vbCrLf & vbCrLf _
  148. 	       & "Where:  ""computer""   is an optional remote computer name" _
  149. 	       & vbCrLf _
  150. 	       & "                     (default is the local computer name)" _
  151. 	       & vbCrLf & vbCrLf _
  152. 	       & "Written by Rob van der Woude" _
  153. 	       & vbCrLf _
  154. 	       & "http://www.robvanderwoude.com"
  155. 	WScript.Echo strMsg
  156. 	WScript.Quit(1)
  157. End Sub
  158.  

page last modified: 2024-04-16; loaded in 0.0065 seconds