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 s
This is in C#, but this is a good article:
http://ryanfarley.com/blog/archive/2004/05/16/649.aspx
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
If you're running on Windows, the following command-line should work from anywhere:
rundll32 url.dll,FileProtocolHandler <your_url>
where <your_url> is the webpage URL to navigate to.
Public Function ShowHelp(ByVal url As String) As System.Diagnostics.Process
Dim startInfo As New Diagnostics.ProcessStartInfo()
startInfo.FileName = "rundll32 url.dll,FileProtocolHandler"
startInfo.Arguments = url
startInfo.WindowStyle = ProcessWindowStyle.Maximized
Return System.Diagnostics.Process.Start(startInfo)
End Function
If you wish to dislay a file the ends in ".html" or "htm" then you can just pass it to the Process.Start() method. The same may work with a URL.
(You must have the flag set that gets Process.Start() to use the shell methods.)
Private Sub helpRichTextBox_LinkClicked(ByVal sender As Object, ByVal e As System.Windows.Forms.LinkClickedEventArgs) Handles helpRichTextBox.LinkClicked
System.Diagnostics.Process.Start(e.LinkText)
End Sub
That's the right way to launch the browser with a URL in general, but if it fails, I would just catch that specific exception, and then attempt to call iexplore <url>
to open the URL in IE, given that it is bound to be installed on any Windows system. (I assume you're not targeting Mono/Linux here.)