How do you find the processor speed (700MHZ, 350MHZ, etc.) in Visual Basic?
Printable View
How do you find the processor speed (700MHZ, 350MHZ, etc.) in Visual Basic?
This gets general system information like is the CPU a PII or PIII?
There is no existing api that gets the cpu speed.Code:
' From allapi.net
Private Declare Sub GetSystemInfo Lib "kernel32" (lpSystemInfo As SYSTEM_INFO)
Private Type SYSTEM_INFO
dwOemID As Long
dwPageSize As Long
lpMinimumApplicationAddress As Long
lpMaximumApplicationAddress As Long
dwActiveProcessorMask As Long
dwNumberOrfProcessors As Long
dwProcessorType As Long
dwAllocationGranularity As Long
dwReserved As Long
End Type
Private Sub Form_Load()
Dim SInfo As SYSTEM_INFO
'KPD-Team 1998
'URL: http://www.allapi.net/
' [email protected]
' Set the graphical mode to persistent
Me.AutoRedraw = True
'Get the system information
GetSystemInfo SInfo
'Print it to the form
Me.Print "Number of procesors:" + str$(SInfo.dwNumberOrfProcessors)
Me.Print "Processor:" + str$(SInfo.dwProcessorType)
Me.Print "Low memory address:" + str$(SInfo.lpMinimumApplicationAddress)
Me.Print "High memory address:" + str$(SInfo.lpMaximumApplicationAddress)
End Sub
But in NT you can get it from the Registry
:rolleyes:Code:Private Declare Function RegCloseKey Lib "advapi32.dll" _
(ByVal hKey As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" _
Alias "RegOpenKeyA" _
(ByVal hKey As Long, _
ByVal lpSubKey As String, _
phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" _
Alias "RegQueryValueExA" _
(ByVal hKey As Long, _
ByVal lpValueName As String, _
ByVal lpReserved As Long, _
lpType As Long, _
lpData As Any, _
lpcbData As Long) As Long
Function cpuSpeed() as long
Dim hKey As Long
Dim cpuSpd As Long
Call RegOpenKey(HKEY_LOCAL_MACHINE, _
"HARDWARE\DESCRIPTION\System\CentralProcessor\0",
hKey)
Call RegQueryValueEx(hKey, "~MHz", 0, 0, cpuSpd, 4)
Call RegCloseKey(hKey)
CPUSpeed = cpuSpd
Thanx to both of you, but I was looking for something like Chin311's response.