如何处理System.ComponentModel.Win32Exception:'访问被拒绝'例外

时间:2018-01-01 13:10:33

标签: c# wpf windows

这是我的代码:

[STAThread]
    public static void Main()
    {
        Process[] localByName = Process.GetProcessesByName("faceme");
        Process currentProcess = Process.GetCurrentProcess();
        int nProcessID = Process.GetCurrentProcess().Id;

        var runningProcess = (from process in Process.GetProcesses()
                              where
                                process.Id != currentProcess.Id &&
                                process.ProcessName.Equals(
                                  currentProcess.ProcessName,
                                  StringComparison.Ordinal)
                              select process).FirstOrDefault();

            if (runningProcess != null)
            {
                runningProcess.Kill();
            }

        MyApp.App app = new MyApp.App();
        app.InitializeComponent();
        app.Run();
    }

当我调用runningProcess.Kill()方法

时出现此错误

0 个答案:

没有答案