Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for physmem.vbs

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

  1. ' PhysMem.vbs,  Version 1.01
  2. ' Display a physical memory summary for the specified computer.
  3. '
  4. ' Written by Rob van der Woude
  5. ' http://www.robvanderwoude.com
  6.  
  7.  
  8. ' Check command line parameters
  9. Select Case WScript.Arguments.Count
  10. 	Case 0
  11. 		' Default if none specified is local computer (".")
  12. 		Set objWMIService = GetObject( "winmgmts://./root/cimv2" )
  13. 		Set colItems = objWMIService.ExecQuery( "Select * from Win32_ComputerSystem", , 48 )
  14. 		For Each objItem in colItems
  15. 			strComputer = objItem.Name
  16. 		Next
  17. 	Case 1
  18. 		' Command line parameter can either be a computer
  19. 		' name or "/?" to request online help
  20. 		strComputer = UCase( Wscript.Arguments(0) )
  21. 		if InStr( strComputer, "?" ) > 0 Then Syntax
  22. 	Case Else
  23. 		' Maximum is 1 command line parameter
  24. 		Syntax
  25. End Select
  26.  
  27. ' Header line for screen output
  28. strMsg = vbCrLf & "Hardware summary for " & strComputer & ":" & vbCrLf & vbCrLf
  29.  
  30. ' Enable error handling
  31. On Error Resume Next
  32.  
  33. ' Connect to specified computer
  34. Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
  35. ' Display error number and description if applicable
  36. If Err Then ShowError
  37.  
  38. ' Query logical memory properties
  39. Set colItems = objWMIService.ExecQuery( "Select * from Win32_LogicalMemoryConfiguration", , 48 )
  40. ' Display error number and description if applicable
  41. If Err Then ShowError
  42. ' Prepare display of results
  43. For Each objItem in colItems
  44. 	strMsg = vbCrLf _
  45. 	       & "Total physical memory :   " _
  46. 	       & Int( ( objItem.TotalPhysicalMemory + 1023 ) / 1024 ) _
  47. 	       & " MB" & vbCrLf & vbCrLf
  48. Next
  49.  
  50. ' Query physical memory properties
  51. Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemory",,48)
  52. ' Display error number and description if applicable
  53. If Err Then ShowError
  54. ' Prepare display of results
  55. For Each objItem in colItems
  56. 	strMsg = strMsg _
  57. 	       & "        Memory module :   " & objItem.DeviceLocator & vbCrLf _
  58. 	       & "        Capacity      :   " & Int( ( objItem.Capacity + 1048575 ) / 1048576 ) & " MB" & vbCrLf _
  59. 	       & "        Rated speed   :   " & objItem.Speed & " MHz" & vbCrLf _
  60. 	       & "        Socket width  :   " & objItem.TotalWidth & " pins" & vbCrLf & vbCrLf
  61. Next
  62.  
  63. ' Add a copyright notice
  64. strMsg = strMsg & "Written by Rob van der Woude" & vbCrLf _
  65.        & "http://www.robvanderwoude.com" & vbCrLf
  66.  
  67. ' Display the results
  68. WScript.Echo strMsg
  69.  
  70. 'Done
  71. WScript.Quit(0)
  72.  
  73.  
  74. Sub ShowError()
  75. 	strMsg = vbCrLf & "Error # " & Err.Number & vbCrLf & _
  76. 	         Err.Description & vbCrLf & vbCrLf
  77. 	Syntax
  78. End Sub
  79.  
  80.  
  81. Sub Syntax()
  82. 	strMsg = strMsg & vbCrLf _
  83. 	       & "PhysMem.vbs,  Version 1.01" & vbCrLf _
  84. 	       & "Display physical memory summary for " _
  85. 	       & "any computer on the network" & vbCrLf & vbCrLf _
  86. 	       & "Usage:  CSCRIPT  //NOLOGO  PHYSMEM.VBS  " _
  87. 	       & "[ computer_name ]" & vbCrLf & vbCrLf _
  88. 	       & "Where:  " & Chr(34) & "computer_name" & Chr(34) _
  89. 	       & " is the optional name of a remote" & vbCrLf _
  90. 	       & "        computer (default is local computer " _
  91. 	       & "name)" & vbCrLf & vbCrLf _
  92. 	       & "Written by Rob van der Woude" & vbCrLf _
  93. 	       & "http://www.robvanderwoude.com" & vbCrLf & vbCrLf _
  94. 	       & "Created with Microsoft's Scriptomatic tool" & vbCrLf _
  95. 	       & "http://www.microsoft.com/technet/treeview/default.asp" _
  96. 	       & "?url=/technet/scriptcenter/WMImatic.asp" & vbCrLf
  97. 	WScript.Echo strMsg
  98. 	WScript.Quit(1)
  99. End Sub
  100.  
  101.  
  102. Private Function Strip( strInput )
  103. 	Do While Left( strInput, 1 ) = " "
  104. 		strInput = Mid( strInput, 2 )
  105. 	Loop
  106. 	Strip = strInput
  107. End Function
  108.  

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