Default Browser
-
I'm trying to launch the default browser, with a given URL in a particular event handler. The best I have so far is:
using (RegistryKey rkey = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Classes\http\shell\open\command")) { string val = rkey.GetValue(String.Empty).ToString(); string browser = val.Split('\"')[1]; Process.Start(browser, URL); }
This works perfectly well on my machine but IE is the only browser I have installed, let alone the default. Can anyone tell me a) If there's a better place to look for the default browser and b) If Netscape, Opera, et al can be parsed out of that key using the same Split? Paul We all will feed the worms and trees
So don't be shy - Queens of the Stone Age, Mosquito Song -
I'm trying to launch the default browser, with a given URL in a particular event handler. The best I have so far is:
using (RegistryKey rkey = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Classes\http\shell\open\command")) { string val = rkey.GetValue(String.Empty).ToString(); string browser = val.Split('\"')[1]; Process.Start(browser, URL); }
This works perfectly well on my machine but IE is the only browser I have installed, let alone the default. Can anyone tell me a) If there's a better place to look for the default browser and b) If Netscape, Opera, et al can be parsed out of that key using the same Split? Paul We all will feed the worms and trees
So don't be shy - Queens of the Stone Age, Mosquito SongKey 1 : HKCR\.html ==> htmlfile Key 2 : HKCR\htmlfile\shell\open\command ==> "c:\....\iexplore.exe" | "...\netscape.exe" | "...."
-
I'm trying to launch the default browser, with a given URL in a particular event handler. The best I have so far is:
using (RegistryKey rkey = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Classes\http\shell\open\command")) { string val = rkey.GetValue(String.Empty).ToString(); string browser = val.Split('\"')[1]; Process.Start(browser, URL); }
This works perfectly well on my machine but IE is the only browser I have installed, let alone the default. Can anyone tell me a) If there's a better place to look for the default browser and b) If Netscape, Opera, et al can be parsed out of that key using the same Split? Paul We all will feed the worms and trees
So don't be shy - Queens of the Stone Age, Mosquito SongJust call Process.Start(URL) and it'll call the default browser for you.
It's not the fall that kills you: it's the sudden stop - Down by Law, Jim Jamursch (1986)
-
Key 1 : HKCR\.html ==> htmlfile Key 2 : HKCR\htmlfile\shell\open\command ==> "c:\....\iexplore.exe" | "...\netscape.exe" | "...."
I did think about using ".html" but I figured it was possible, if unlikely, that someone might have it set up so that double-clicking an .html file would open a different browser from the default. Daniel seems to have the perfect answer, but thanks anyway :) Paul We all will feed the worms and trees
So don't be shy - Queens of the Stone Age, Mosquito Song -
Just call Process.Start(URL) and it'll call the default browser for you.
It's not the fall that kills you: it's the sudden stop - Down by Law, Jim Jamursch (1986)
Nice answer Daniel. Didn't really give much thought to that idea, I didn't think it would work with a URL like "www.mydomain.com/mysite" (ie. no mention of http or html) but somehow it does. Very cool, thanks. Paul We all will feed the worms and trees
So don't be shy - Queens of the Stone Age, Mosquito Song