Results 1 to 4 of 4

Thread: CPU Utilization

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    Greece
    Posts
    164

    CPU Utilization

    Hello,

    does anyone know if there's an API call that returns the CPU utilization ?

    Thanks

  2. #2
    jim mcnamara
    Guest
    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

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    Greece
    Posts
    164

    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

  4. #4
    jim mcnamara
    Guest
    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
  •  



Click Here to Expand Forum to Full Width