
Question:
What RegKey can you get the default browser application's path from?
Best way to get to it from C#/.NET?
Solution:1
Here's the key you want:
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\http\shell\open\command
And here's a quick registry tutorial for C#, if you need it.
Edit:
For per-user settings, use this key:
HKEY_CLASSES_ROOT\http\shell\open\command
(HKCR has both machine and user settings, user takes priority).
Note that this might not work on Vista. For more info, see here.
Solution:2
for windows 7 default browser path save in following registry key
HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\ Associations\UrlAssociations\http
by using c# you can get it as follows -
RegistryKey regkey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\shell\\Associations\\UrlAssociations\\http\\UserChoice", false); string browser = regkey.GetValue("Progid").ToString();
Solution:3
Based on your answers I wrote this sample code that should do what you want (not tested)
public static string GetDefaultBrowserPath() { string defaultBrowserPath = null; RegistryKey regkey; // Check if we are on Vista or Higher OperatingSystem OS = Environment.OSVersion; if ((OS.Platform == PlatformID.Win32NT) && (OS.Version.Major >= 6)) { regkey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\shell\\Associations\\UrlAssociations\\http\\UserChoice", false); if (regkey != null) { defaultBrowserPath = regkey.GetValue("Progid").ToString(); } else { regkey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Classes\\IE.HTTP\\shell\\open\\command", false); defaultBrowserPath = regkey.GetValue("").ToString(); } } else { regkey = Registry.ClassesRoot.OpenSubKey("http\\shell\\open\\command", false); defaultBrowserPath = regkey.GetValue("").ToString(); } return defaultBrowserPath; }
Solution:4
I just made a function for this:
public void launchBrowser(string url) { string browserName = "iexplore.exe"; using (RegistryKey userChoiceKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice")) { if (userChoiceKey != null) { object progIdValue = userChoiceKey.GetValue("Progid"); if (progIdValue != null) { if(progIdValue.ToString().ToLower().Contains("chrome")) browserName = "chrome.exe"; else if(progIdValue.ToString().ToLower().Contains("firefox")) browserName = "firefox.exe"; else if (progIdValue.ToString().ToLower().Contains("safari")) browserName = "safari.exe"; else if (progIdValue.ToString().ToLower().Contains("opera")) browserName = "opera.exe"; } } } Process.Start(new ProcessStartInfo(browserName, url)); }
Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
EmoticonEmoticon