Hello,
How do I get the usernames of all the processes running in task manager using c#?
Thanks
Hello,
How do I get the usernames of all the processes running in task manager using c#?
Thanks
Look into Win32_Process Class, and GetOwner Method
public string GetProcessOwner(int processId)
{
string query = "Select * From Win32_Process Where ProcessID = " + processId;
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
ManagementObjectCollection processList = searcher.Get();
foreach (ManagementObject obj in processList)
{
string[] argList = new string[] { string.Empty, string.Empty };
int returnVal = Convert.ToInt32(obj.InvokeMethod("GetOwner", argList));
if (returnVal == 0)
{
// return DOMAIN\user
return argList[1] + "\\" + argList[0];
}
}
return "NO OWNER";
}
You can check this article http://www.codeproject.com/KB/cs/processownersid.aspx