. Net (C #): Use WMI to query the process PID in performancecounter

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.