Private Const sCPURegKey _ = "HARDWARE\DESCRIPTION\System\CentralProcessor\0"
Private Const HKEY_LOCAL_MACHINE As Long = &H80000002
And Declare
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
Private Declare Function RegCloseKey Lib "advapi32.dll" _
(ByVal HKey As Long) As Long
This is the Function to use.
Private Function GetCPUSpeed() As Long
Dim HKey As Long
Dim cpuSpeed As Long
'Open CPU key
Call RegOpenKey(HKEY_LOCAL_MACHINE, sCPURegKey, HKey)
'and retrieve the value
Call RegQueryValueEx(HKey, "~MHz", 0, 0, cpuSpeed, 4)
Call RegCloseKey(HKey)
GetCPUSpeed = cpuSpeed
End Function
Finally you can return the value to a control, in this example I choose a button(Command1) event and a textbox named “txtCPUSpeed.txt”.
Private Sub Command1_Click()
txtCPUSpeed = " " & GetCPUSpeed() & " MHz"
End Sub
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.