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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KarenAnalyst 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
grayeCommented:
0
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.