Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / programming / Internet

Opening the Internet Browser Programmatically

5.00/5 (2 votes)
18 Aug 2011CPOL 11.1K  
Given below is code for opening the Internet browser programmatically in VB 6 and VB.NET.VB 6Private Declare Function ShellExecute Lib shell32.dll Alias _ ShellExecuteA (ByVal hwnd As Long, ByVal lpOperation As String, _ ByVal lpFile As String, ByVal lpParameters As...

Given below is code for opening the Internet browser programmatically in VB 6 and VB.NET.


VB 6

VB
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

Private Sub btnWebsite_Click()
    ShellExecute Me.hwnd, "open", "http://www.codeproject.com/", _
                 vbNullString, vbNullString, vbNormal
End Sub

VB.NET

This will open the URL in the default browser:


VB
System.Diagnostics.Process.Start("http://www.codeproject.com")

This will open the website in Internet Explorer. Here you have the option to change the browser in your code.


VB
System.Diagnostics.Process.Start("iexplore.exe", "http://www.codeproject.com")

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)