Windows RegKey - Default Browser Application Path

27,147

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

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));
    }

Solution 4

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;
    }
Share:
27,147
BuddyJoe
Author by

BuddyJoe

I like to code C# and work with the web. Still learning.

Updated on April 08, 2020

Comments

  • BuddyJoe
    BuddyJoe about 4 years

    What RegKey can you get the default browser application's path from?

    Best way to get to it from C#/.NET?

  • mhenry1384
    mhenry1384 over 14 years
    You almost certainly want the "HKEY_CLASSES_ROOT" one, NOT the HKEY_LOCAL_MACHINE one. HKEY_CLASSES_ROOT will always return the browser the user will be expecting.
  • Nyerguds
    Nyerguds over 10 years
    On Win7, that "Progid" doesn't seem to contain link, though. It contains a program ID to be looked up in the registry under "HKCR/FetchedProgramId" (with FetchedProgramId the program id valut fetched before). Under that key is, again, a "\shell\open\command", in which you find the actual path.
  • Fractal
    Fractal about 7 years
    This didn't seem to give the path on Windows 10. It only returned a value of IE.HTTP
  • 8oris
    8oris over 2 years
    It's the same for WIndow 10 !