Pipo
Pipo

Reputation: 5601

c# : Close chromium browsers without close google chrome browsers

I would like to close chromium web processs

enter image description here

without closing google chrome browser which are running

enter image description here

The code bellow close chromium browsers but also google chrome browsers, that I don't want to :

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

Do you know how to do this?

Upvotes: 6

Views: 1553

Answers (1)

JimDel
JimDel

Reputation: 4359

This may work if you know the path to Chromium. Plus, You will have to compile the code as 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();
    }
}

Also keep in mind this comparison needs to be case sensitive.

Upvotes: 3

Related Questions