Jump to content

Recommended Posts

Posted

I've looked all over the help file but cant seem to find this simple answer.

How do I get the CPU load percentage?

[center][/center][center]=][u][/u][/center][center][/center]

Posted

Have a look at this by Ascend4nt >>

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

I tried with the following code

$hPDHQuery=_PDH_GetNewQueryHandle()
$aCPUCounters=_PDH_GetCPUCounters($hPDHQuery,$sPCName)
$iTotalCPUs=@extended
     _PDH_CollectQueryData($hPDHQuery)
  _PDH_CollectQueryData($hPDHQuery)
  $cpu = 0
   For $i=0 To $iTotalCPUs-1
            $iCounterValue=_PDH_UpdateCounter($hPDHQuery,$aCPUCounters[$i][1],0,True)
            If $i<>$iTotalCPUs-1 Then
                $cpu&=$iCounterValue&" %"
            Else
                $cpu&=$iCounterValue&"%"
            EndIf
        Next
_PDH_FreeQueryHandle($hPDHQuery)
_PDH_UnInit()

But the result I get is.

"00 %0 %0%"

[center][/center][center]=][u][/u][/center][center][/center]

Posted (edited)

I fixed it with code

$hPDHQuery=_PDH_GetNewQueryHandle()
$aCPUCounters=_PDH_GetCPUCounters($hPDHQuery,$sPCName)
$iTotalCPUs=@extended 
    _PDH_CollectQueryData($hPDHQuery) 
Sleep(50)  $cpu = ""   
    _PDH_CollectQueryData($hPDHQuery) 
  For $i=0 To $iTotalCPUs-1      
      $iCounterValue=_PDH_UpdateCounter($hPDHQuery,$aCPUCounters[$i][1],1,True) 
        ConsoleWrite($iCounterValue&@CRLF)             
   $cpu = $iCounterValue&"%"          
  Next
_PDH_FreeQueryHandle($hPDHQuery)
_PDH_UnInit()
Edited by IchBistTod

[center][/center][center]=][u][/u][/center][center][/center]

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...