Click here to Skip to main content
15,074,394 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,

Please help me with how to close all browser windows using C#.

I am using ClientScript.RegisterStartupScript(typeof(Page), "closePage", "self.close();", true);
to close the window ,But it works only in IE and not working in other browsers.
Posted
Updated 23-Jul-18 18:26pm
Comments
   
It smells huge abuse. No wonder it work only on IE, a greatest supporter of abusers... :-)
—SA

1 solution

We can close our browser using Process. See the following code
using System.Diagnostics;

Process[] AllProcesses = Process.GetProcesses();
            foreach (var process in AllProcesses)
            {
                if (process.MainWindowTitle != "")
                {
                    string s = process.ProcessName.ToLower();
                    if (s == "iexplore" || s == "iexplorer" || s == "chrome" || s == "firefox" )
                        process.Kill();
                }
            }
   
v2
Comments
priya9826 8-Jul-14 10:59am
   
Thanks for posting the code.But the above code will closes all the browsers in the computer.I am looking for the code for the below scenario:

When I run the asp.net website,It will opens the webpage in google chrome.On click of button,it needs to close the web page.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900