Sh4d3bl4st Posted June 29, 2010 Share Posted June 29, 2010 Hey Guys, I'm working on a programm to get the CPU usage of all running processes. Or at least the top 5 ones. I searched in various Forums and Google for a while, but I didn't get a clue how to do this. I already got a formula how to calculate this, but It doesn't work with the script I wrote. Maybe you could have a look for yourself and help me ^^ Please be patient with my programming style expandcollapse popupFunc _ProcessListProperties() Local $sUserName, $sMsg, $load[1], $time[1], $CPU[1], $sUserDomain, $avProcs, $procs, $objWMI, $colItems, $values[1] $procs = ProcessList() ReDim $values[$procs[0][0]][2] ReDim $time[$procs[0][0]] ReDim $load[$procs[0][0]] ReDim $CPU[$procs[0][0]][2] $objWMI = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") If IsObj($objWMI) Then For $i = 2 To ($procs[0][0]) $colItems = $objWMI.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfProc_Process WHERE IDProcess = '" & $procs[$i][1] & "'") For $objItem In $colItems $CPU[($i - 2)][0] = $procs[$i][0] $load[($i - 2)] = $objItem.PercentProcessorTime $time[($i - 2)] = $objItem.TimeStamp_Sys100NS Next Next For $i = 2 To ($procs[0][0]) $colItems = $objWMI.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfProc_Process WHERE IDProcess = '" & $procs[$i][1] & "'") For $objItem In $colItems $values[($i - 2)][0] = $objItem.PercentProcessorTime - $load[($i - 2)] $values[($i - 2)][1] = $objItem.TimeStamp_Sys100NS - $time[($i - 2)] Next Next EndIf For $i = 0 To _ArrayMaxIndex($values) $CPU[$i][1] = $values[$i][0] / $values[$i][1] Next For $i = 0 To _ArrayMaxIndex($values) $CPU[$i][1] = Round($CPU[$i][1] * 100, 0) Next _ArraySort($CPU, 1, -1, -1, 1) Return $CPU EndFunc ;==>_ProcessListProperties Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 29, 2010 Moderators Share Posted June 29, 2010 Sh4d3bl4st,Welcome to the AutoIt forum. I have used this UDF successfully to read CPU usage by process.Did you try using the forum Search facility - I recommend it, even if it is a bit quirky at times. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Sh4d3bl4st Posted June 29, 2010 Author Share Posted June 29, 2010 Thx for the fast answer. As you can see I found pretty much the same code. But the one I found didn't work like this one ^^ Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now