How to know the CPU and memory usage of a process with WMI?

I'm pretty sure you want the WMI perf classes Win32_PerfFormattedData_PerfProc_Process or Win32_PerfRawData_PerfProc_Process

E.g. their properties PercentProcessorTime and WorkingSet

Note that the Perf classes take a bit effort to understand.

  • There are gotchas with the Formatted versions (See Hey, Scripting Guy! article Why Does My Performance Monitoring Script Keep Returning the Same Incorrect Values?)
  • And the Raw Data classes need care to translate the "CounterType" into the right math formula to use to calculate the values based on the raw data. See How's My Driving? Monitoring Performance Using WMI for a starting place.

But those WMI classes should give you all the info you're looking for.


Win32_Process also has UserModeTime and KernelModeTime which can be used to calculate CPU usage

Also look at http://technet.microsoft.com/en-us/library/ee176718.aspx


Please see:

  • WMI Made Easy For C#

  • How to get current CPU and RAM usage in Python?

Might also be of interest:

  • Get current memory utilisation of a process running on a remote machine with WMI

Tags:

Windows

Wmi