• .NET Core想使用默认浏览器打开URL已不能用Process.Start()方法了?
  • 发布于 2个月前
  • 172 热度
    0 评论
在 .NET Framework 时代,如果想使用默认浏览器打开一个 URL 可以使用以下代码:
Process.Start("https://www.duidaima.com");
但该代码在 .NET 6.0 中执行会出错:
An error occurred trying to start process ‘https://www.duidaima.com’ with working directory ‘xxxx’.
系统找不到指定的文件。

出现该错误的原因是 .NET CORE 改变了 ProcessStartInfo 类的默认值。在默认情况下 UseShellExecute 的取值由 .NET Framework 中的 True 变为了 False 。所以,要解决该报错只需将 UseShellExecute 设置为 True 即可:
Process.Start(new ProcessStartInfo("https://www.duidaima.com") { UseShellExecute = true });

用户评论