C#如果进程具有管理权限,则获取进程完整位置

时间:2016-02-07 11:55:14

标签: c# process

我使用按钮开发了一个测试c#app,当您单击该按钮时,它会检查一个活动进程,然后打印它的完整位置。 一切正常,直到您以管理员身份运行其他程序(右键单击“以管理员身份运行”) 然后我在这里得到例外:full_location = proc.MainModule.FileName;

有没有办法获得具有管理权限的流程的位置? 如果我使用app.manifest“requestedExecutionLevel level =”requireAdministrator“uiAccess =”false“编译应用程序,那么它甚至适用于以管理员身份运行的进程。 但是否存在非行政特权的方式?

我使用的代码:

    private void btn_test_Click(object sender, EventArgs e)
    {

        string full_location = "";
        Process[] theprocesses = Process.GetProcessesByName("NT037");//That particular program name

        foreach (Process proc in theprocesses)
        {
            full_location = proc.MainModule.FileName;//<-- An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll


            Console.WriteLine(full_location + " (NT037)");                
        }
    }

0 个答案:

没有答案