Sign in to follow this  
Followers 0
AcidCorps

Process CPU

4 posts in this topic

I've been working on a script to get information about running processes

I used PsaltyDS Function _ProcessListProperties as an exmaple but I'm having trouble with the CPU% part, it always returns 100 for [system Process] and 0 for everythign else

#include <Array.au3>
#include <Process.au3>

$ProcList1 = ProcessList()

Dim $ProcList[$ProcList1[0][0] + 1][8]
Dim $a, $b, $c, $d, $e, $f, $g, $h

$ProcList[0][0] = $ProcList1[0][0]

$o_WMI = ObjGet('winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2')
$o_Procs = $o_WMI.ExecQuery ('select * from win32_process')

For $o_Proc In $o_Procs
    For $i = 1 To $ProcList[0][0] - 1
        If $o_Proc.ProcessID = $ProcList1[$i][1] Then
            $ProcList[$i][0] = $ProcList1[$i][0] ;Name
            $ProcList[$i][1] = $ProcList1[$i][1] ;PiD
            $ProcList[$i][3] = $o_Proc.ParentProcessId ;Parent PiD
            $ProcList[$i][2] = _ProcessGetName($ProcList[$i][3]) ;Parent Process Name
            $ProcList[$i][4] = $o_Proc.ExecutablePath ;Executable Path
            $ProcList[$i][5] = $o_Proc.WorkingSetSize ;Memory Used
            $ProcList[$i][6] = $o_Proc.PageFileUsage ;Page File Used
        EndIf
    Next
Next

$o_Refresh = ObjCreate('WbemScripting.SWbemRefresher')
$c_Procs = $o_Refresh.AddEnum ($o_WMI, 'Win32_PerfFormattedData_PerfProc_Process'  ).objectSet
$o_Refresh.Refresh
Local $i_Time = TimerInit()
Do
    Sleep(10)
Until TimerDiff($i_Time) > 100
$o_Refresh.Refresh

For $o_Proc In $c_Procs
    For $i = 1 To $ProcList[0][0] - 1
        If $ProcList[$i][1] = $o_Proc.IDProcess Then
            $ProcList[$i][7] = $o_Proc.PercentProcessorTime ;CPU Load
            ExitLoop
        EndIf
    Next
Next

_ArrayDisplay($ProcList)

Share this post


Link to post
Share on other sites



It works fine for me, and System Process usually takes up 100% CPU.

Share this post


Link to post
Share on other sites

ok, thanks for the test then

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0