Opening default web browser from Windows Application

This post deals with opening default web browser from a .NET Application (esp. a Windows Application).

First, copy the following code and paste it in your class.

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

Then, you can use the function ShellExecute() as follows.

Private Sub Button1_Click()
   Dim objBrowser As Long
   objBrowser = ShellExecute(0, "open", "", 0, 0, 1)
End Sub

We can also open the default web browser as:


I usually create a Form and place a WebBrowser control in it and use it for opening any web pages. I will get back to you with that soon.

Microsoft reference for the topic, Click here

This entry was posted in Code Snippets and tagged , , , by Pranav. Bookmark the permalink.

About Pranav

A Software Engineer by profession and a Geek at heart. I love exploring new technologies and working on algorithmic problems. As of now, I write code for bread, butter and satisfaction. I like to develop applications, and generally that involves much more than writing code. It’s not just about hurling code, but producing something meaningful that has a measurable and positive impact, helps others and solves interesting problems.

One thought on “Opening default web browser from Windows Application

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s