【发布时间】:2015-07-10 00:13:03
【问题描述】:
是否有可靠的编程方式来确定 Microsoft Edge 是默认浏览器?
我知道一种选择是使用IApplicationAssociationRegistration::QueryCurrentDefault 方法返回为http 注册的默认应用程序。虽然不清楚此调用返回的 ProgID 是固定字符串,但它可能不是验证 Edge 确实是默认浏览器的最佳方法。
【问题讨论】:
标签: microsoft-edge
是否有可靠的编程方式来确定 Microsoft Edge 是默认浏览器?
我知道一种选择是使用IApplicationAssociationRegistration::QueryCurrentDefault 方法返回为http 注册的默认应用程序。虽然不清楚此调用返回的 ProgID 是固定字符串,但它可能不是验证 Edge 确实是默认浏览器的最佳方法。
【问题讨论】:
标签: microsoft-edge
使用下面的代码sn-p。尚未使用 Firefox 或任何其他奇怪的工具进行测试,但您将根据 Windows 10 中的默认浏览器获得以下返回值。
下面的代码 sn-p 应该可以工作。在控制台应用程序中测试。如果有人想要 VB 版本,请告诉我。
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;
}
}
希望这会有所帮助。坦帕的希利。
【讨论】:
IApplicationAssociationRegistration::QueryCurrentDefault 一样,您最终会得到一个用于 Edge 的 ProgID——问题是,ProgID 是否可靠(不太可能改变)。