【发布时间】:2021-06-01 01:45:27
【问题描述】:
我想使用默认浏览器(在我的情况下为 Chrome)从 VB.NET 应用程序打开网页。
我使用这个代码:
Dim BrowserRegistryString As String = My.Computer.Registry.ClassesRoot.OpenSubKey("\http\shell\open\command\").GetValue("").ToString
Dim DefaultBrowserPath As String = System.Text.RegularExpressions.Regex.Match(BrowserRegistryString, "(\"".*?\"")").Captures(0).ToString
Process.Start(DefaultBrowserPath, "http://www.example.com")
它工作得很好,除了它在 Microsoft Edge 中打开网站,如果我在 shell 中使用“start http://www.example.com”,它会在 Chrome 中打开网站。 Chrome 被设置为我的默认浏览器(来自 Windows 10 配置面板),所以...
...那个谜是从哪里来的?
【问题讨论】:
-
如果你想打开默认的WebBrowser,为什么不直接
Process.Start("http://www.example.com")? -
因为它不起作用。我得到了这个异常:“System.ComponentModel.Win32Exception:'找不到文件'
-
您使用的是什么 .Net 版本? + 您是否尝试过运行提升的应用程序?或者添加
runas动词? -
我使用了 .NET 5.0 我不知道“运行提升的应用程序”和“添加 runas 动词”是什么意思。 ://
-
在任何.Net Core 应用程序(或从.Net Core 派生,如.Net 5)中,UseShellExecute 为
false,而在.Net Framework 中为true。因此,您需要使用Process.ProcessStartInfo将其设置为true。 -- elevated 应用程序以管理员权限运行,与使用runas verb 相同,要求用户授予调用进程管理员权限。