In my previous article: getting the process PID in the process performancecounter, I demonstrated using the ID process performance counter in the process type to return the process ID in the performance counter. WMI has one type: win32_perfformatteddata_perfproc_process. It can also be used to return the normalized information in the process performance counter, and a WMI class with unnormalized information: win32_perfrawdata_perfproc_process.
The name attribute of this WMI class is equivalent to the process name in the performance counter, and the idprocess attribute is equal to the ID of the process (that is, the return value of the ID process performance counter ). Of course, this WMI type also contains a lot of process information, more information can refer to msdn: http://msdn.microsoft.com/en-us/library/aa394277 (V = vs.85). aspx
It is easy to use, that is, regular WMI query routines:
// + Using system. Management;
VaR objsearcher = new managementobjectsearcher ("select * From win32_perfformatteddata_perfproc_process ");
Foreach (managementobject mobj in objsearcher. Get ())
Console. writeline ("{0} {1}", mobj ["name"], mobj ["idprocess"]);
Output:
Idle 0
System 4
SMSs 296
CSRSS 400
Wininit 480
CSRSS #1 488
Services 536
LSASS 552
LSM 560.
Svchost 660
Winlogon 708
... Omitted...
Process and PID are listed.