//Beschreibung:
ermittelt den Owner eines Prozesses, z.B. für Pageant
//Beispiel:
Process[] procPageant = Process.GetProcessesByName("myprocessname");
bool blPageantRunning = false;
foreach (Process p in procPageant)
{
string procOwner = getLocalProcessOwner(p.Id);
//Aktion für jeden Prozess, z.B. Log
}
private static string getLocalProcessOwner(int pid)
{
string ProcessOwner = "";
ObjectQuery x = new ObjectQuery("Select * From Win32_Process where Handle='" + pid + "'");
ManagementObjectSearcher mos = new ManagementObjectSearcher(x);
foreach (ManagementObject mo in mos.Get())
{
string[] s = new string[2];
mo.InvokeMethod("GetOwner", (object[])s);
ProcessOwner = s[0].ToString();
break;
}
return ProcessOwner;
}
1 Kommentare zum Snippet