How to determine if Microsoft Edge is the default browser?

末鹿安然 提交于 2019-12-04 10:43:25

Use the following code snippet. Haven't tested with Firefox or any of the other strange ones, but you'll get the following return values based on your default browser in Windows 10.

  • Chrome - ChromeHTML
  • Edge - AppXq0fevzme2pys62n3e0fbqa7peapykr8v
  • Internet Explorer - IE.HTTP

Code snippet below should work. Tested in a console app. If anyone wants a VB version let me know.

using Microsoft.Win32;
public static class BrowserUtils
{
    static public string GetSystemDefaultBrowser()
    {
        string _retval = string.Empty;
        const string userChoice = @"Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice";
        using (RegistryKey userChoiceKey = Registry.CurrentUser.OpenSubKey(userChoice))
        {
            if (userChoiceKey == null)
            {
                _retval = "unknown-> userChoiceKey returned null";
            }

            object progIdValue = userChoiceKey.GetValue("Progid");
            if (progIdValue == null)
            {
                _retval = "unknown->GetValue(Progid) returned null";
            }
            //_retval = String.Format("progId=[{0}]", progIdValue.ToString());
            _retval = progIdValue.ToString();
        }
        return _retval;
    } 
} 

Hope this helps. Healy in Tampa.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!