Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for cputype.vbs

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

  1. ' Check command line parameters
  2. Select Case WScript.Arguments.Count
  3. 	Case 0
  4. 		' Default if none specified is local computer (".")
  5. 		Set objWMIService = GetObject( "winmgmts://./root/cimv2" )
  6. 		Set colItems = objWMIService.ExecQuery( "Select * from Win32_ComputerSystem", , 48 )
  7. 		For Each objItem in colItems
  8. 			strComputer = objItem.Name
  9. 		Next
  10. 	Case 1
  11. 		' Command line parameter can either be a computer
  12. 		' name or "/?" to request online help
  13. 		strComputer = UCase( Wscript.Arguments(0) )
  14. 		if InStr( strComputer, "?" ) > 0 Then Syntax
  15. 	Case Else
  16. 		' Maximum is 1 command line parameter
  17. 		Syntax
  18. End Select
  19.  
  20. ' Define constants
  21. Const wbemFlagReturnImmediately = &h10
  22. Const wbemFlagForwardOnly = &h20
  23.  
  24. ' Header line for screen output
  25. strMsg = vbCrLf & "CPU type for " & strComputer & ":" & vbCrLf & vbCrLf
  26.  
  27. ' Enable error handling
  28. On Error Resume Next
  29.  
  30. ' Connect to specified computer
  31. Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
  32. ' Display error number and description if applicable
  33. If Err Then ShowError
  34.  
  35. ' Query processor properties
  36. Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", _
  37.                                           wbemFlagReturnImmediately + wbemFlagForwardOnly)
  38. ' Display error number and description if applicable
  39. If Err Then ShowError
  40. ' Prepare display of results
  41. For Each objItem In colItems
  42. 	strMsg = strMsg _
  43. 	       & "Device ID : " & objItem.DeviceID      & vbCrLf _
  44. 	       & "CPU Type  : " & Strip( objItem.Name ) & vbCrLf & vbCrLf
  45. Next
  46.  
  47. ' Display results
  48. WScript.Echo strMsg
  49.  
  50. 'Done
  51. WScript.Quit(0)
  52.  
  53.  
  54. Sub ShowError()
  55. 	strMsg = vbCrLf & "Error # " & Err.Number & vbCrLf & _
  56. 	         Err.Description & vbCrLf & vbCrLf
  57. 	Syntax
  58. End Sub
  59.  
  60.  
  61. Sub Syntax()
  62. 	strMsg = strMsg & vbCrLf _
  63. 	       & "CPUType.vbs,  Version 1.00" & vbCrLf _
  64. 	       & "Display CPU type for any computer " _
  65. 	       & "on the network" & vbCrLf & vbCrLf _
  66. 	       & "Usage:  CSCRIPT  //NOLOGO  CPUTYPE.VBS  " _
  67. 	       & "[ computer_name ]" & vbCrLf & vbCrLf _
  68. 	       & "Where:  " & Chr(34) & "computer_name" & Chr(34) _
  69. 	       & " is the optional name of a remote" & vbCrLf _
  70. 	       & "        computer (default is local computer " _
  71. 	       & "name)" & vbCrLf & vbCrLf _
  72. 	       & "Written by Rob van der Woude" & vbCrLf _
  73. 	       & "http://www.robvanderwoude.com" & vbCrLf & vbCrLf _
  74. 	       & "Created with Microsoft's Scriptomatic 2.0 tool" & vbCrLf _
  75. 	       & "http://www.microsoft.com/downloads/details.aspx?" & vbCrLf _
  76. 	       & "    FamilyID=09dfc342-648b-4119-b7eb-783b0f7d1178&DisplayLang=en" & vbCrLf
  77. 	WScript.Echo strMsg
  78. 	WScript.Quit(1)
  79. End Sub
  80.  
  81.  
  82. Private Function Strip( strInput )
  83. 	Do While Left( strInput, 1 ) = " "
  84. 		strInput = Mid( strInput, 2 )
  85. 	Loop
  86. 	Strip = strInput
  87. End Function
  88.  

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