I found some code that will tell me the owner of a process. My problem is that it only works if the application has Administrator privileges. Is there any way to do the same thing as an unelevated process? Currently I get "Access Denied" error from the InvokeMethod call.
string query = "Select * from Win32_Process Where Name = \"" + sExeName + "\"";
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
//string owner = argList[1] + "\\" + argList[0];
//return owner;
processUser = argList[1] + "\\" + argList[0];
if (processUser == currentUser)
continue;
else
break;
}
}