我使用了以下功能打开用户的默认Web浏览器。
I am using the function below to open the user's default web browser.
Public Function ShowHelp(ByVal url As String) As System.Diagnostics.Process
Dim startInfo As New Diagnostics.ProcessStartInfo()
startInfo.FileName = url
startInfo.WindowStyle = ProcessWindowStyle.Maximized
Return System.Diagnostics.Process.Start(startInfo)
End Function
有几次该函数返回的错误(对用户机)的系统找不到指定文件的
我猜的用户没有设置默认的Web浏览器。 为什么我得到这个错误?我怎么能调用此函数之前添加默认的Web浏览器检查?
I guess the user has not set a default web browser. Why i get this error? How could i add a default web browser check before calling this function?
这是在C#中,但是这是一个很好的文章:
This is in C#, but this is a good article:
http://ryanfarley.com/blog/archive/2004/ 5月16日/ 649.aspx
下面是C#作为VB.NET:
Here's the C# as VB.NET:
Private Function getDefaultBrowser() As String
Dim browser As String = String.Empty
Dim key As RegistryKey = Nothing
Try
key = Registry.ClassesRoot.OpenSubKey("HTTP\shell\open\command", False)
'trim off quotes
browser = key.GetValue(Nothing).ToString().ToLower().Replace("""", "")
If Not browser.EndsWith("exe") Then
'get rid of everything after the ".exe"
browser = browser.Substring(0, browser.LastIndexOf(".exe") + 4)
End If
Finally
If key IsNot Nothing Then
key.Close()
End If
End Try
Return browser
End Function