Windows RegKey - Default Browser Application Path

后端 未结 4 1321
失恋的感觉
失恋的感觉 2021-01-18 03:13

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

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

相关标签:
4条回答
  • 2021-01-18 03:54

    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.

    0 讨论(0)
  • 2021-01-18 04:06

    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));
        }
    
    0 讨论(0)
  • 2021-01-18 04:08

    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();
    
    0 讨论(0)
  • 2021-01-18 04:10

    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;
        }
    
    0 讨论(0)
提交回复
热议问题