title speaks it all.
Asked
Active
Viewed 1.0k times
6
-
1Can you add some detail about *why* you are trying to do this to give some context? – jerryjvl Jun 09 '09 at 06:31
-
I could use a quick way to toggle default browser when developing. – Nifle Jun 09 '09 at 09:19
-
2Why would he need to give detail? The question is simple. – msbg Oct 14 '12 at 18:29
3 Answers
7
The default browser is saved as an entry in the registry key of windows. The values are saved on a protocol basis like this
HKEY_CLASSES_ROOT\[protocol]\shell\open\command
Where protocol can be http, https, etc. On how to access/modify registry values inside C#, you can take a look at this article

Sambatyon
- 3,316
- 10
- 48
- 65
5
I think you will need to modify atleast two RegistryKeys and set the path to the alternative browser:
HKEY_CLASSES_ROOT\http\shell\open\command
HKEY_CLASSES_ROOT\htmlfile\shell\open\command
An alternative may be to create an additional entry under the Shell key and set it as the default action:
[HKEY_CLASSES_ROOT\http\shell]
(default) set to OpenWithMyBrowser
[HKEY_CLASSES_ROOT\http\shell\OpenWithMyBrowser\command]
(default) set to "MyBrowser.exe"

Cerebrus
- 25,615
- 8
- 56
- 70
2
for the windows 7 pc you need to change registry key for the
HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\ Associations\UrlAssociations\http
you can change that using c#
RegistryKey regkey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\shell\\Associations\\UrlAssociations\\http\\UserChoice", true);
string browser = regkey.GetValue("Progid").ToString();
if (browser != "IE.HTTP")
{
regkey.SetValue("Progid", "IE.HTTP");
}
for prior to vista os - (checked in windows XP)
RegistryKey regkey = Registry.ClassesRoot.OpenSubKey("http\\shell\\open\\command", true);
string browser = regkey.GetValue(null).ToString().ToLower().Replace("\"", "");
string defBrowser = "";
if (!browser.EndsWith("exe"))
{
//get rid of everything after the ".exe"
browser = browser.Substring(0, browser.LastIndexOf(".exe") + 4);
defBrowser = browser.Substring(browser.LastIndexOf("\\") + 1);
}
if (defBrowser != "iexplore")
{
Process.Start("IExplore.exe");
ScreenScraperEngine.Instance.Wait(2000);
string iepath = "";
foreach (Process p in Process.GetProcesses())
{
if (p.ProcessName == "IEXPLORE")
{
iepath = p.MainModule.FileName;
}
}
if (iepath != "")
{
string iepathval = "\"" + iepath + "\" -nohome";
regkey.SetValue(null, iepathval);
}
}

DevT
- 4,843
- 16
- 59
- 92