Process.kill() denied in Windows 7 32bits even with Administrator privileges

后端 未结 4 1411
清歌不尽
清歌不尽 2020-12-20 20:46

Hello every one.

I\'m faced with a weird problem. My application has a simple method that in case IE enters a state were it gets unresponsive this m

相关标签:
4条回答
  • 2020-12-20 21:05

    It is a quirk of Internet Explorer, it starts multiple processes for one session. Killing one of them can cause all of them to exit. You probably see the "process has exited" exception. Do it like this instead:

            foreach (var ie in Process.GetProcessesByName("iexplore")) { 
                try {
                   ie.Kill();
                }
                catch {}
            }
    
    0 讨论(0)
  • 2020-12-20 21:05

    you shouldn't use "foreach" to kill it, and between two kill, you need delay for the process to be killed completely

    0 讨论(0)
  • 2020-12-20 21:09

    Did you wrap your code in a try/catch block to see if an exception was thrown? If not, try

    try
    {            
        foreach (System.Diagnostics.Process exe in System.Diagnostics.Process.GetProcesses())   
        {   
            if (exe.ProcessName.StartsWith("iexplore"))   
                exe.Kill();   
        } 
    }
    
    catch (Win32Exception e)
    {
        Console.WriteLine("The process is terminating or could not be terminated.");
    }
    
    catch (InvalidOperationException e)
    {
        Console.Writeline("The process has already exited.");
    }
    
    catch (Exception e)  // some other exception
    {
        Console.WriteLine("{0} Exception caught.", e);
    }
    
    0 讨论(0)
  • 2020-12-20 21:10

    Given that you say you always possess administrative privileges when you attempt to call this method, the following would explain why you have intermittent issues:

    System.Diagnostics.Process.Kill:

    If the call to the Kill method is made while the process is currently terminating, a Win32Exception is thrown for Access Denied.

    If you've quickly hit 'delete' + 'OK' twice, on an entry in Process-Explorer, you'll know what I'm talking about.

    0 讨论(0)
提交回复
热议问题