I wrote the codes below to close all IE (Internet Explorer) Processes.
private void Kill_IE()
{
Process[] ps = Process.GetProcessesByName("IEXPLORE");
foreach (Process p in ps)
{
p.Kill();
}
}
The problem is some opened IE windows show an alert :
alert("do not close my web site"); //in JavaScript
or a
confirm_box("do you really want to exit?" , "YES|NO"); //in JavaScript
before exit(Unload_Form) and my program can't close those windows.
How can i ignore those alerts and force close those windows?
Edit :
The ways below can't close that browser with that annoying alert...
Show the black console :
Process.Start("taskkill", "/im iexplore.exe /f /t");
Hide the black Console :
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "taskkill.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = "/f /t /im iexplore.exe";
Process.Start(startInfo);
Any Idea?
I've tested this code and it works every time for me. I'm using IE11 and have opened both remote and local sites that generate alerts and the processes still close without an error.
I suggest wrapping this process in a try/catch to see if there any exceptions generated as I believe the fault lies elsewhere.