Windows RegKey - Default Browser Application Path

后端 未结 4 1367
失恋的感觉
失恋的感觉 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 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;
        }
    

提交回复
热议问题