Cosmin Ioniță
Cosmin Ioniță

Reputation: 4055

Open a new window of Google Chrome from C#

It is possible to open a new instance of Chrome from C#?

By instance I mean a new separate tab, not contained in an existing chrome window.

I've tried the following solutions but both of them create a new tab in an existing chrome window or creates an instance if no one exists:

Process.Start(@"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", "www.google.com");

Process.Start("chrome.exe", "www.google.com");

I want to create always a separate window, even if there are existing Chrome windows.

To be clear, at the end I want something like that (when I hover on the chrome icon in the taskbar):

enter image description here

And not something like that:

enter image description here

I've searched everywhere and I haven't found a clear answer that says me if this is even possible or not from C#.

Thank you.

Upvotes: 12

Views: 22757

Answers (2)

abdul
abdul

Reputation: 1592

You can do it by passing --new-window argument to the process

x86

Process process = new Process();
process.StartInfo.FileName = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe";
process.StartInfo.Arguments = "google.com" + " --new-window";
process.Start();

x64

Process process = new Process();
process.StartInfo.FileName = @"C:\Program Files\Google\Chrome\Application\chrome.exe";
process.StartInfo.Arguments = "google.com" + " --new-window";
process.Start();

Upvotes: 20

BitQuestions
BitQuestions

Reputation: 760

Shorter version, looking first for chrome then for firefox (the syntax is different)

strURL="http://myurl.com";
try
{
    //Launch Chrome in a new window
    System.Diagnostics.Process.Start("chrome", strURL+" --new-window");             
}
catch
{
    try
    { 
        //Chrome not found ... launch Firefox in a new window
        System.Diagnostics.Process.Start("firefox", "-new-window "+ strURL);
    }
    catch
    {
        //WARN THE USER TO INSTALL A BROWSER...
    }
}           

Upvotes: 6

Related Questions