使用默认浏览器打开自定义 URL

问题描述 投票:0回答:1

如果我有一个像

www.google.com
这样的普通网址,我可以用以下命令打开它:

Process.Start(new ProcessStartInfo
{
    FileName = url,
    UseShellExecute = true
});

问题在于自定义 URL,例如:

pma.wsdd.dock

我收到此错误:

System.ComponentModel.Win32Exception
  HResult=0x80004005
  Message=An error occurred trying to start process 'pma.wsdd.dock'

我知道问题是 shell 无法将其识别为 URL/URI,我唯一能想到的就是尝试强制执行用户的默认浏览器。

但我找不到任何示例来获取或运行用户在 Windows 11 上默认拥有的浏览器。

c# winforms .net-8.0 windows-11
1个回答
0
投票

解决方案是添加协议。

例如:

  • http://pma.wsdd.dock
  • https://pma.wsdd.dock
  • ftp://pma.wsdd.dock
  • {other-protocol-prefix}pma.wsdd.dock
© www.soinside.com 2019 - 2024. All rights reserved.