0

我找到了一些可以告诉我进程所有者的代码。我的问题是它只有在应用程序具有管理员权限时才有效。有没有办法做与未提升的过程相同的事情?目前,我从 InvokeMethod 调用中收到“拒绝访问”错误。

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;
    }
}
4

0 回答 0