Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determine CPU Speed from VBScript 1

Status
Not open for further replies.

Dinobrago

Technical User
Dec 8, 2001
184
US
I am writing a Windows shell script and I need to report the CPU speed of the PC the script is running on. Any ideas how to do this?

Dino
 
Well, for NT machines (NT4, NT5 a.k.a. Win2K, NT5.1 a.k.a. WinXP) with Pentium or later processors...

The CPU speed is stored in the Registry.

Some sample code, but it's gonna wrap:
Code:
Dim WSH, sRpt, i, iSpeed
Const csPfx = "HKLM\HARDWARE\DESCRIPTION\System\CentralProcessor\"

Function CPU(ByVal iProc, ByVal sKey)
  CPU = WSH.RegRead(csPfx & CStr(iProc) & sKey)
End Function

Set WSH = Wscript.CreateObject("WScript.Shell")

For i = 0 to 7
  On Error Resume Next ' Make sure CPU # is valid.
  iSpeed = CPU(i, "\~MHZ")
  If Err.Number = 0 Then
    sRpt = sRpt & "CPU " & CStr(i) & vbCrLf
    sRpt = sRpt & CPU(i, "\Identifier") & vbCrLf
    sRpt = sRpt & CPU(i, "\VendorIdentifier") & vbCrLf
    sRpt = sRpt & "Speed " & CStr(iSpeed) & "Mhz" & vbCrLf
  End If
  Err.Clear
Next

MsgBox sRpt

Set WSH = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top