How to determine if Microsoft Edge is the default

2019-04-11 15:44发布

Is there a reliable, programmatic way to determine that Microsoft Edge is the default browser?

I know one option would be to use the IApplicationAssociationRegistration::QueryCurrentDefault method to return the default application registered for http. It's unclear that the ProgID returned by this call is a fixed string though so it may not be the best way to verify that Edge is indeed the default browser.

1条回答
Anthone
2楼-- · 2019-04-11 16:43

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.

查看更多
登录 后发表回答