c#:关闭Chrome浏览器,不使用谷歌浏览器

时间:2018-05-01 12:57:22

标签: c# .net process chromium

我想关闭chromium网络流程

enter image description here

没有关闭正在运行的google chrome浏览器

enter image description here

代码低于铬浏览器,但谷歌浏览器浏览器,我不想:

 var chromeAndChomiumProcesses = Process.GetProcessesByName("chrome");
 foreach (var chromeAndChomiumProcess in chromeAndChomiumProcesses)
 {
        chromeAndChomiumProcess.Kill();
 }

你知道怎么做吗?

1 个答案:

答案 0 :(得分:1)

如果您知道Chromium的路径,这可能会有效。另外,您必须将代码编译为x64。

Process[] chrome = Process.GetProcessesByName("chrome");

foreach (var chromeProcess in chrome)
{
    string fullPath = chromeProcess.MainModule.FileName;
    string expectedPath = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";

    if (fullPath.Equals(expectedPath))
    {
        chromeProcess.Kill();
    }
}

另请注意,此比较需要区分大小写。