Click here to Skip to main content
15,608,053 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:

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.
Updated 23-Jul-18 18:26pm
Sergey Alexandrovich Kryukov 7-Jul-14 18:49pm    
It smells huge abuse. No wonder it work only on IE, a greatest supporter of abusers... :-)

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" )
Share this answer
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 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