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 ' Note that if you declare the lpData parameter as String, you must pass it By Value.
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 RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Sub Command1_Click()
Unload Me
End Sub
Private Sub Form_Load()
ProgressBar1.Max = 100
ProgressBar1.Min = 0
ProgressBar1.Value = 0
getcpuusage
End Sub
Private Sub getcpuusage()
Dim lData As Long, lType As Long, lSize As Long
Dim hKey As Long
Qry = RegOpenKey(HKEY_DYN_DATA, "PerfStats\statData", hKey)
If Qry <> 0 Then
MsgBox "can't Query CPU Usage information"
End
End If
lType = REG_DWORD
lSize = 4
Qry = RegQueryValueEx(hKey, "KERNEL\CPUUsage", 0, lType, lData, lSize)
ProgressBar1.Value = Int(lData)
Label1.Caption = "Current CPU Usage:" & lData & "%"
Qry = RegCloseKey(hKey)
End Sub