Windows RegKey - Default Browser Application Path

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

提交回复
热议问题