是否有可靠的编程方式来确定Microsoft Edge是默认浏览器?
我知道一个选择是使用 IApplicationAssociationRegistration :: QueryCurrentDefault方法来返回为http注册的默认应用程序。虽然尚不清楚此调用返回的ProgID是固定字符串,所以它可能不是验证Edge确实是默认浏览器的最佳方法。
使用以下代码段。尚未使用Firefox或其他任何奇怪的软件进行测试,但是您将基于Windows 10中的默认浏览器获得以下返回值。
下面的代码段应该可以正常工作。在控制台应用程序中测试。如果有人想要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;
}
}
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助。Healy在坦帕。
| 归档时间: |
|
| 查看次数: |
2271 次 |
| 最近记录: |