VB 6 find path to users default browser

I need to use the shell command to open a browser using the shell command from within my VB 6 application.  I need to find a way to determine the default browser and its path.  Any ideas?
motokentAsked:
Who is Participating?
 
KarenConnect With a Mentor Analyst programmerCommented:
Here is the code I use... call it by using:

LaunchWebBrowser "http://www.yahoo.com"


Private Declare Function ShellExecute Lib "shell32.dll" _
    Alias "ShellExecuteA" ( _
    ByVal hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) _
As Long

Public Sub LaunchWebBrowser(Optional URL As String = vbNullString)
Const SW_SHOW  As Long = 1
Const HTTP     As String = "http://"
Dim s          As String
Dim j          As Long
   
    s = URL
    If s <> vbNullString Then
        If Left(s, Len(HTTP)) <> HTTP Then
            s = HTTP & s
        End If
    End If

    j = ShellExecute(0&, "open", s, vbNullString, vbNullString, SW_SHOW)
    If j = 0 Then
        ' Error occurred.
    End If
End Sub
0
 
grayeCommented:
Best approach is to use the FindExecutable API.  You just feed it a temporary file name with an ".htm" extension, and it will return the path to the broswer.
http://msdn.microsoft.com/en-us/library/bb776419(VS.85).aspx 
0
 
grayeConnect With a Mentor Commented:
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
motokentAuthor Commented:
Dumb question....
Where does this statement go?:  "Declare Function ShellExecute... As Long"
I get error message "Only comments can appear after End Sub..."

Here's what I have in my Form1 code page:

Public Sub LaunchWebBrowser(Optional URL As String = vbNullString)
Const SW_SHOW  As Long = 1
Const HTTP     As String = "http://"
Dim s          As String
Dim j          As Long
   
    s = URL
    If s <> vbNullString Then
        If Left(s, Len(HTTP)) <> HTTP Then
            s = HTTP & s
        End If
    End If

    j = ShellExecute(0&, "open", s, vbNullString, vbNullString, SW_SHOW)
    If j = 0 Then
        MsgBox ("fred") ' Error occurred.
    End If
End Sub


Private Sub Command1_Click()

Declare Function ShellExecute Lib "shell32.dll" _
    Alias "ShellExecuteA" ( _
    ByVal hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) _
As Long

LaunchWebBrowser "http://www.yahoo.com"

End Sub
0
 
motokentAuthor Commented:
Thanks.
0
 
KarenAnalyst programmerCommented:
You have to put all API declarations at the top of the form, in the same place where you would declare module-level variables. So just move it up the very top of all of your form code, i.e.


Declare Function ShellExecute Lib "shell32.dll" _
    Alias "ShellExecuteA" ( _
    ByVal hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) _
As Long



Public Sub LaunchWebBrowser(Optional URL As String = vbNullString)
Const SW_SHOW  As Long = 1
Const HTTP     As String = "http://"
Dim s          As String
Dim j          As Long
   
    s = URL
    If s <> vbNullString Then
        If Left(s, Len(HTTP)) <> HTTP Then
            s = HTTP & s
        End If
    End If

    j = ShellExecute(0&, "open", s, vbNullString, vbNullString, SW_SHOW)
    If j = 0 Then
        MsgBox ("fred") ' Error occurred.
    End If
End Sub


Private Sub Command1_Click()

LaunchWebBrowser "http://www.yahoo.com"

End Sub

0
 
motokentAuthor Commented:
thank again.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.