如何确定Microsoft Edge是否是默认浏览器? [英] How to determine if Microsoft Edge is the default browser?

查看:283
本文介绍了如何确定Microsoft Edge是否是默认浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可靠的编程方式确定Microsoft Edge是默认浏览器?

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

我知道一种选择是使用 IApplicationAssociationRegistration :: QueryCurrentDefault 方法可返回为http注册的默认应用程序.虽然尚不清楚此调用返回的ProgID是否为固定字符串,所以它可能不是验证Edge确实是默认浏览器的最佳方法.

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.

推荐答案

使用以下代码段.尚未使用Firefox或其他任何奇怪的工具进行测试,但是您将基于Windows 10中的默认浏览器获得以下返回值.

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

下面的代码段应该可以使用.在控制台应用程序中测试.如果有人想要VB版本,请告诉我.

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.

这篇关于如何确定Microsoft Edge是否是默认浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆