Jump to content
Sign in to follow this  

how to get the CPU usage and memory of running process

Recommended Posts


how can i get the CPU usage and memory of a running process in a remote computer? i just need to collect all the process but i want to add the CPU and memory usage on the collection. i have the script that list all the process but don't know how to get the CPU and Memory then combine it all in one list. can someone give me idea how to do it?

function process starts with this code:

Func _Process() 
    Local $sUserName, $sUserDomain
    Dim $Process[1][6], $i = 1  
    $strComputer = GUICtrlRead($host)
    $ping = Ping($strComputer)
    If $ping Then       
        $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
        $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)    

        If IsObj($colItems) Then
            For $objItem In $colItems
                ReDim $Process[UBound($Process) + 1][6]             
                $Process[$i][0] = $objItem.Name
                If $objItem.GetOwner($sUserName, $sUserDomain) = 0 Then $Process[$i][1] = $sUserDomain & "\" & $sUserName
                $Process[$i][2] = $objItem.ProcessId
                $Process[$i][3] = $objItem.Priority
                $Process[$i][4] = $objItem.ExecutablePath
                $Process[$i][5] = $objItem.CommandLine              
                If $objItem.GetOwner($sUserName, $sUserDomain) = 0 Then $Process[$i][5] = $sUserDomain & "\" & $sUserName
                $i += 1
                $Process[0][0] = UBound($Process) - 1
                If $Process[0][0] < 1 Then
                    SetError(1, 1, 0)
                    SetError(1, 2, 0)

        For $i = 1 To UBound($Process) - 1
            $tmp = $Process[$i][0] & "|" & $Process[$i][1] & "|" & $Process[$i][2] & "|" & $Process[$i][3] & "|" & $Process[$i][4] & "|" & $Process[$i][5]  
            GUICtrlCreateListViewItem($tmp, $listview)

Share this post

Link to post
Share on other sites

Don't forget to follow that topic to the last post:

The function _ProcessListProperties() has a new home in Example Scripts. Please take criticism/suggestions to that topic.


That function is maintained in it's own Example Scripts topic now, and updates are only posted there: _ProcessListProperties(), List many properties of a process

In particular, note the unresolved memory leak issue that arises if you run the function in a tight loop (a work-around is presented).


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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