使用C#关闭所有浏览器窗口(IE,谷歌浏览器,Firefox) [英] Close the all browser windows(IE,google chrome,firefox) using C#

查看:924
本文介绍了使用C#关闭所有浏览器窗口(IE,谷歌浏览器,Firefox)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





请帮我看看如何使用C#关闭所有浏览器窗口。



我正在使用ClientScript.RegisterStartupScript(typeof(Page),closePage,self.close();,true);

关闭窗口,但它仅适用于IE而不能在其他浏览器中工作。

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.

推荐答案

我们可以使用Process关闭浏览器。请参阅以下代码

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();
                }
            }


这篇关于使用C#关闭所有浏览器窗口(IE,谷歌浏览器,Firefox)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆