The question below has the answer to "How do I open the default Browser to a URL in C#?" But how do I open the default browser in C# without navigating to a URL? Desired behavior is for the default browser to open to the home page, or use the startup behavior (for example, defined in the Firefox option "When Firefox starts").
Asked
Active
Viewed 1,091 times
0
-
Which operating system are you trying to do this on? – itsme86 Apr 12 '17 at 17:35
-
1It's not going to be easy, because the URL you want is `about:home`, but you can't just hand that to the operating system. That means you'll have to figure out what the default browser is, get the path to it, then pass the URL as a command line argument. – Apr 12 '17 at 17:46
-
@itsme86, Platform is WPF, Windows 7/8/10. – Nathan Kovner Apr 12 '17 at 18:21
-
1You can start by reading [this](https://superuser.com/questions/445612/how-to-find-default-browser-in-registry-windows-7) to find the default browser command line. Then it's just a matter of reading the registry which is simple in C#, and then running the command designated in the registry key using [Process.Start()](https://msdn.microsoft.com/en-us/library/system.diagnostics.process.start(v=vs.110).aspx). – itsme86 Apr 12 '17 at 18:26
1 Answers
0
This should do it:
Process p = new Process();
p.StartInfo = new StartInfo(url) {UseShellExecute = true};
p.Start();
EDIT: This will work for a valid URL. As the comment above say this will not work for http://about:home.
EDIT #2: I will keep the previous code in case it's helpful for anybody. Since the comment above I've been looking how to do it, and in deed was not so trivial, this is what I did in order to launch the default browser without navigating to any URL
.
using (var assoc = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice"))
{
using (var cr = Registry.ClassesRoot.OpenSubKey(assoc.GetValue("ProgId") + @"\shell\open\command"))
{
string loc = cr.GetValue("").ToString().Split('"')[1];
// In windows 10 if Microsoft edge is the default browser
// loc=C:\Windows\system32\LaunchWinApp.exe, so launch Microsoft Edge manually
// 'cause didn't figured it out how to launc ME with that exe
if (Path.GetFileNameWithoutExtension(loc) == "LaunchWinApp")
Process.Start("explorer", @"shell:Appsfolder\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge");
else
Process.Start(loc);
}
}
I tested it in my machine (Win10) and worked out for every default browser switch. Hope it helps now.

dcg
- 4,187
- 1
- 18
- 32
-
1The OP specifically says "But how do I open the default browser in C# **without navigating to a URL**". Your answer requires a URL to navigate to. You see the problem, right? – itsme86 Apr 12 '17 at 18:11
-