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.