How to determine if Microsoft Edge is the default browser?

半城伤御伤魂 提交于 2020-01-01 11:58:07

问题


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:


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.



来源:https://stackoverflow.com/questions/31330445/how-to-determine-if-microsoft-edge-is-the-default-browser

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