Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for cpuspeedtd.vbs

(view source code of cpuspeedtd.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 & "Computer Name" & vbTab & "CPU ID" & vbTab _
  26.        & "Current Clock Speed" & vbTab & "Maximum Clock Speed" & vbCrLf
  27.  
  28. ' Enable error handling
  29. On Error Resume Next
  30.  
  31. ' Connect to specified computer
  32. Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
  33. ' Display error number and description if applicable
  34. If Err Then ShowError
  35.  
  36. ' Query processor properties
  37. Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", _
  38.                                           wbemFlagReturnImmediately + wbemFlagForwardOnly)
  39. ' Display error number and description if applicable
  40. If Err Then ShowError
  41. ' Prepare display of results
  42. For Each objItem In colItems
  43. 	strMsg = strMsg _
  44. 	       & strComputer & vbTab & objItem.DeviceID & vbTab _
  45. 	       & objItem.CurrentClockSpeed & vbTab & objItem.MaxClockSpeed & 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. 	       & "CPUSpeedTD.vbs,  Version 1.00" & vbCrLf _
  65. 	       & "Display CPU speed for each processor on any computer on the network" & vbCrLf _
  66. 	       & "in tab delimited format" & vbCrLf & vbCrLf _
  67. 	       & "Usage:  CSCRIPT  //NOLOGO  CPUSPEEDTD.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.0058 seconds