dazza Posted May 27, 2010 Share Posted May 27, 2010 The ProcessList, ProcessGetStats doesnt return memory and CPU like Windows Task Manager does. Is it possible for AutoIT to get the memory used/CPU usage per process without having to open Task Manager? Many thanks. Link to comment Share on other sites More sharing options...
water Posted May 27, 2010 Share Posted May 27, 2010 You can get a lot of information using WMI. Please see this example created by Scriptomatic (can be found on the forum):expandcollapse popup; Generated by AutoIt Scriptomatic $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $Output="" $Output = $Output & "Computer: " & $strComputer & @CRLF $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems $Output = $Output & "Caption: " & $objItem.Caption & @CRLF $Output = $Output & "CommandLine: " & $objItem.CommandLine & @CRLF $Output = $Output & "CreationClassName: " & $objItem.CreationClassName & @CRLF $Output = $Output & "CreationDate: " & WMIDateStringToDate($objItem.CreationDate) & @CRLF $Output = $Output & "CSCreationClassName: " & $objItem.CSCreationClassName & @CRLF $Output = $Output & "CSName: " & $objItem.CSName & @CRLF $Output = $Output & "Description: " & $objItem.Description & @CRLF $Output = $Output & "ExecutablePath: " & $objItem.ExecutablePath & @CRLF $Output = $Output & "ExecutionState: " & $objItem.ExecutionState & @CRLF $Output = $Output & "Handle: " & $objItem.Handle & @CRLF $Output = $Output & "HandleCount: " & $objItem.HandleCount & @CRLF $Output = $Output & "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF $Output = $Output & "KernelModeTime: " & $objItem.KernelModeTime & @CRLF $Output = $Output & "MaximumWorkingSetSize: " & $objItem.MaximumWorkingSetSize & @CRLF $Output = $Output & "MinimumWorkingSetSize: " & $objItem.MinimumWorkingSetSize & @CRLF $Output = $Output & "Name: " & $objItem.Name & @CRLF $Output = $Output & "OSCreationClassName: " & $objItem.OSCreationClassName & @CRLF $Output = $Output & "OSName: " & $objItem.OSName & @CRLF $Output = $Output & "OtherOperationCount: " & $objItem.OtherOperationCount & @CRLF $Output = $Output & "OtherTransferCount: " & $objItem.OtherTransferCount & @CRLF $Output = $Output & "PageFaults: " & $objItem.PageFaults & @CRLF $Output = $Output & "PageFileUsage: " & $objItem.PageFileUsage & @CRLF $Output = $Output & "ParentProcessId: " & $objItem.ParentProcessId & @CRLF $Output = $Output & "PeakPageFileUsage: " & $objItem.PeakPageFileUsage & @CRLF $Output = $Output & "PeakVirtualSize: " & $objItem.PeakVirtualSize & @CRLF $Output = $Output & "PeakWorkingSetSize: " & $objItem.PeakWorkingSetSize & @CRLF $Output = $Output & "Priority: " & $objItem.Priority & @CRLF $Output = $Output & "PrivatePageCount: " & $objItem.PrivatePageCount & @CRLF $Output = $Output & "ProcessId: " & $objItem.ProcessId & @CRLF $Output = $Output & "QuotaNonPagedPoolUsage: " & $objItem.QuotaNonPagedPoolUsage & @CRLF $Output = $Output & "QuotaPagedPoolUsage: " & $objItem.QuotaPagedPoolUsage & @CRLF $Output = $Output & "QuotaPeakNonPagedPoolUsage: " & $objItem.QuotaPeakNonPagedPoolUsage & @CRLF $Output = $Output & "QuotaPeakPagedPoolUsage: " & $objItem.QuotaPeakPagedPoolUsage & @CRLF $Output = $Output & "ReadOperationCount: " & $objItem.ReadOperationCount & @CRLF $Output = $Output & "ReadTransferCount: " & $objItem.ReadTransferCount & @CRLF $Output = $Output & "SessionId: " & $objItem.SessionId & @CRLF $Output = $Output & "Status: " & $objItem.Status & @CRLF $Output = $Output & "TerminationDate: " & WMIDateStringToDate($objItem.TerminationDate) & @CRLF $Output = $Output & "ThreadCount: " & $objItem.ThreadCount & @CRLF $Output = $Output & "UserModeTime: " & $objItem.UserModeTime & @CRLF $Output = $Output & "VirtualSize: " & $objItem.VirtualSize & @CRLF $Output = $Output & "WindowsVersion: " & $objItem.WindowsVersion & @CRLF $Output = $Output & "WorkingSetSize: " & $objItem.WorkingSetSize & @CRLF $Output = $Output & "WriteOperationCount: " & $objItem.WriteOperationCount & @CRLF $Output = $Output & "WriteTransferCount: " & $objItem.WriteTransferCount & @CRLF Next ConsoleWrite($Output) FileWrite(@TempDir & "\Win32_Process.TXT", $Output ) Run(@Comspec & " /c start " & @TempDir & "\Win32_Process.TXT" ) Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_Process" ) Endif Func WMIDateStringToDate($dtmDate) Return (StringMid($dtmDate, 5, 2) & "/" & _ StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _ & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2)) EndFuncDetailed information about the returned values can be found here. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
dazza Posted May 27, 2010 Author Share Posted May 27, 2010 This is spot on. Many thanks. I can correlate PageFileUsage to 'memory' but I don't know enough to find the correlation for CPU usage? Can you answer this riddle and put me forever in your debt. Link to comment Share on other sites More sharing options...
water Posted May 27, 2010 Share Posted May 27, 2010 I haven't used this WMI stuff myself, i just searched the forum.Here is a tool that delivers a lot of performance information. Maybe you can have a look at the source and see how the CPU calculations are done.This seems to solve your problem. It returns CPU and memory usage. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
dazza Posted May 28, 2010 Author Share Posted May 28, 2010 This is perfect. Many, many thanks 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