. Net (C #): Call the WMI method to obtain the User Name of the process.

Source: Internet
Author: User

When WMI queries the win32_process type, the user information (username and domain name) of the created process is not included in the attribute list. After checking msdn, only getowner (or getownersid) is called) method. (Refer to the getowner method: http://msdn.microsoft.com/en-us/library/aa390460 (V = vs.85). aspx)

This method has two out parameters, namely the user name and domain name, which are both string types.

 

In. net, the WMI instance method is called through managementobject. invokemethod.

// Create the win32_process WMI class

VaR mgrcls = new managementclass ("win32_process ");

// Enumerate all instances

Foreach (managementobject mobj in mgrcls. getinstances ())

{

// Prepare the parameter. The length is 2.

Object [] pas = new object [2];

 

Mobj. invokemethod ("getowner", PAS );

 

Console. writeline ("{0} {1} \ {2}", mobj ["name"], PAS [1], PAS [0]);

}

Console. readkey (true );

 

Note:

Run the program as an administrator. Otherwise, the System user cannot be displayed.

 

Result:

 

Nt authority \ System, nt authority \ Local Service, and nt authority \ Network Service are equivalent to system, Local Service, and network service system users in the task manager, they all use different levels of system accounts to run Windows Services.

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.