Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for cpuspeed.vbs

(view source code of cpuspeed.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 speed 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. 	       & "Current Clock Speed : " & objItem.CurrentClockSpeed & vbCrLf _
  45. 	       & "Maximum Clock Speed : " & objItem.MaxClockSpeed     & vbCrLf & vbCrLf
  46. Next
  47.  
  48. ' Display results
  49. WScript.Echo strMsg
  50.  
  51. 'Done
  52. WScript.Quit(0)
  53.  
  54.  
  55. Sub ShowError()
  56. 	strMsg = vbCrLf & "Error # " & Err.Number & vbCrLf & _
  57. 	         Err.Description & vbCrLf & vbCrLf
  58. 	Syntax
  59. End Sub
  60.  
  61.  
  62. Sub Syntax()
  63. 	strMsg = strMsg & vbCrLf _
  64. 	       & "CPUSpeed.vbs,  Version 1.00" & vbCrLf _
  65. 	       & "Display CPU speed for each processor on " _
  66. 	       & "any computer on the network" & vbCrLf & vbCrLf _
  67. 	       & "Usage:  CSCRIPT  //NOLOGO  CPUSPEED.VBS  " _
  68. 	       & "[ computer_name ]" & vbCrLf & vbCrLf _
  69. 	       & "Where:  " & Chr(34) & "computer_name" & Chr(34) _
  70. 	       & " is the optional name of a remote" & vbCrLf _
  71. 	       & "        computer (default is local computer " _
  72. 	       & "name)" & vbCrLf & vbCrLf _
  73. 	       & "Written by Rob van der Woude" & vbCrLf _
  74. 	       & "http://www.robvanderwoude.com" & vbCrLf & vbCrLf _
  75. 	       & "Created with Microsoft's Scriptomatic 2.0 tool" & vbCrLf _
  76. 	       & "http://www.microsoft.com/downloads/details.aspx?" & vbCrLf _
  77. 	       & "    FamilyID=09dfc342-648b-4119-b7eb-783b0f7d1178&DisplayLang=en" & vbCrLf
  78. 	WScript.Echo strMsg
  79. 	WScript.Quit(1)
  80. End Sub
  81.  

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