|
-
Jun 6th, 2001, 10:31 AM
#1
Thread Starter
Addicted Member
CPU Utilization
Hello,
does anyone know if there's an API call that returns the CPU utilization ?
Thanks
-
Jun 6th, 2001, 04:00 PM
#2
Works For Win 9x & Me NOT NT! Use the Registry -
Code:
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 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 Const REG_DWORD = 4
Private Const HKEY_DYN_DATA = &H80000006
'
Public Sub InitCPU()
Dim Data As Long, Size As Long
Dim hKey As Long, hRet As Long
hRet = RegOpenKey(HKEY_DYN_DATA, "PerfStats\StartStat", hKey)
hRet = RegQueryValueEx(hKey, "KERNEL\CPUUsage", 0, REG_DWORD, Data, 4)
hRet = RegCloseKey(hKey)
End Sub
'
Public Function GetCPU() As Long
Dim Data As Long, Size As Long
Dim hKey As Long
Dim hRet As Long
hRet = RegOpenKey(HKEY_DYN_DATA, "PerfStats\StatData", hKey)
hRet = RegQueryValueEx(hKey, "KERNEL\CPUUsage", 0&, REG_DWORD, Data, 4)
GetCPUUsage = Data
hRet = RegCloseKey(hKey)
End Function
-
Jun 6th, 2001, 05:05 PM
#3
Thread Starter
Addicted Member
Thanks Jim
Thank you Jim, this worked OK for me.
Well... I didn't know that the registry was being updated all
the time at the HKEY_DYN_DATA section.... (you learn something
everyday !!!!)
I am not quite sure about the InitCPU sub though.. Why should I
use it since the CPU utilization info that I need is on /StatData sub-section ?
Thanks
-
Jun 6th, 2001, 05:52 PM
#4
Init messes with a different key, as you may have noticed. It starts things off. The other key is cumulative.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|