I am trying to test the following code snippet.
static void StartAndKill()
{
Process ieProc = Process.Start("iexplore.exe", "www.apress.com");
Console.WriteLine("--> Hit enter to kill {0}\t", ieProc.ProcessName);
Console.ReadLine();
try
{
Console.WriteLine(ieProc.Id);
ieProc.Kill();
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
}
}
This should kill the internet explorer window and close it. Instead I get an exception that says:
Cannot process request because the process (7256) has exited.
What is the logical explanation for this behaviour?
The error message is misleading. The real reason why the process doesn’t get killed is administrative privs on Windows 7 are not defaulted. If I open a command prompt by using “Run as administrator”, the code does what it is supposed to do. I will move to close this question.
Thanks to all those who responded.