打开默认浏览器的问题



我想从VB打开一个网页。. NET应用程序使用默认浏览器(在我的情况下是Chrome)。

我使用以下代码:

Dim BrowserRegistryString As String = My.Computer.Registry.ClassesRoot.OpenSubKey("httpshellopencommand").GetValue("").ToString
Dim DefaultBrowserPath As String = System.Text.RegularExpressions.Regex.Match(BrowserRegistryString, "("".*?"")").Captures(0).ToString
Process.Start(DefaultBrowserPath, "http://www.example.com")

它工作得很好,除了它在Microsoft Edge中打开网站,尽管如果我使用"start http://www.example.com"在shell中,它在Chrome中打开该网站。Chrome被设置为我的默认浏览器(从Windows 10配置面板),所以…

…这种神秘感从何而来?

这是我使用的代码,它像一个魅力。我想有更好的方法来提取默认的浏览器路径没有参数…

Public Function GetDefaultBrowser() As String
Dim strDefaultBrowserPathTemp As String
Dim intPosDefaultBrowserFileExtension As Int16
Using userChoiceKey As RegistryKey = Registry.CurrentUser.OpenSubKey("SoftwareMicrosoftWindowsShellAssociationsUrlAssociationshttpUserChoice")
If userChoiceKey IsNot Nothing Then
Dim progIdValue As Object = userChoiceKey.GetValue("Progid")
If progIdValue IsNot Nothing Then
strDefaultBrowserPathTemp = My.Computer.Registry.GetValue("HKEY_CLASSES_ROOT" & userChoiceKey.GetValue("Progid") & "shellopencommand", "", Nothing).ToString
intPosDefaultBrowserFileExtension = strDefaultBrowserPathTemp.IndexOf(".exe" & Chr(34))
Return Left(strDefaultBrowserPathTemp, intPosDefaultBrowserFileExtension + Len(".exe" & Chr(34)))
End If
End If
End Using
End Function