Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 478
Cosmin Ioniță Avatar asked Nov 29 '16 07:11

Cosmin Ioniță


People also ask

How do I get Google Chrome to open in a new window?

Just add chrome to you task bar. Right click and choose new window. Easy cheesy...

How do I open Chrome with CMD?

Open Chrome Using Command PromptOpen Run by typing “Run” in the Windows 10 search bar and selecting the “Run” application. Here, type Chrome and then select the “OK” button. The web browser will now open.

How do I clone a window in Chrome?

Press Alt+Shift+D to duplicate the current tab (Option+Shift+D on Mac).

How do I get Chrome to open links in a new window instead of a new tab?

Firstly, go to settings and then click on the search settings. Secondly, access the “Where results Open” and then pick the “Open each selected result in a new browser window” option.


2 Answers

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...
    }
}           
like image 122
BitQuestions Avatar answered Oct 04 '22 07:10

BitQuestions


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();
like image 39
abdul Avatar answered Oct 04 '22 07:10

abdul