5

I'm trying to use C# to open two separate browser windows side by side. I've tried using Process.Start(url) but that causes Chrome to open new tabs instead of new windows. This seems to work on IE, however I'd like to have code that can work with different types of browsers, namely: IE, Chrome, Firefox, and Safari. How do I detect the default browser and then open two separate windows side-by-side? Additionally, I want to be able to position the two windows next to each other, is that possible?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
user1715925
  • 607
  • 9
  • 26
  • 2
    Why do you want this? As a user, having two chrome windows open, possibly in addition to my main browser window, would annoy me to no end. – Mike Caron Oct 31 '12 at 03:08

2 Answers2

4

If you want to open new window in chrome instead of new tab, this code worked for me

  Process process = new System.Diagnostics.Process();
  process.StartInfo.FileName = "chrome";
  process.StartInfo.Arguments = <yoururl> + " --new-window"; 
  process.Start();
Guillermo Zooby
  • 582
  • 2
  • 15
  • 32
0

This is more about the way that the browser is configured than how the process is called from C#. In both cases, the system simply calls the default program assigned to handle the URL. There may or may not be arguments to that command, but typically it will simply invoke chrome.exe <url> and from there, the chrome.exe process decides how to handle the parameter.

The only method I am aware of would be to examine the registry (under HKEY_CLASSES_ROOT\http\shell\open\command) and parse the string value. Once you know the specific browser, you may be able to control the presentation using command-line arguments. Of course, this is specific to Windows and may be a pain to manage.

If the browser does not support setting a geometry from the command line, you will need to use FindWindow and SetWindowPos (using P/Invoke) to manipulate the window locations.

I am not sure about your application, but would embedding a WebBrowser Control meet your needs? Then you would have total control of the presentation.

jheddings
  • 26,717
  • 8
  • 52
  • 65
  • I tried using the WebBrowser control but that turns out to require a lot of work to make it work seamlessly as a normal browser. With my purpose it's more than enough to use default browser on the system. As per my original question, I actually found that I could pass in the options for opening new window to the `System.Diagnostics.Process` object by changing the arguments. For example, Chrome uses `--new-window` and Firefox uses `-new-window`. I only need to find out whether I can position the two windows side-by-side. If not, I can live without it. – user1715925 Oct 31 '12 at 02:33