Open an External File, URL, Email and System Apps in VB6

The ShellExecute function allows you to open external application, specific URL location, email address or launch system applications upon clicking on a single button.
1. Start a new Standard Exe Project.
2. Add this code in General Declarations.
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
3. Add a command button on your form, change its name to cmdOpen.
4. DoubleClick on the form and try any of the codes below.
'# Open file (quotes are used so that the actual value that is passed is "C:\test.txt"
Private Sub cmdOpen_Click()

    ShellExecute 0, vbNullString, """"C:\test.txt"""", vbNullString, vbNullString, vbNormalFocus

End Sub

'# Open url
Private Sub cmdOpen_Click()

    ShellExecute 0, vbNullString, "http://tutorpinoy.blogspot.com", vbNullString, vbNullString, vbNormalFocus

End Sub

'# Open email address
Private Sub cmdOpen_Click()

    ShellExecute 0, vbNullString, "mailto:tu2rpinoy@gmail.com", vbNullString, vbNullString, vbNormalFocus

End Sub

'#Open System Apps
Private Sub cmdOpen_Click()

    ShellExecute 0, vbNullString, "Notepad", vbNullString, vbNullString, vbNormalFocus

End Sub

Comments

  1. Very nice tutorial' Keep up the good work

    ReplyDelete

Post a Comment

Popular posts from this blog

How to Create a Configuration.INI Files in VB6

How to Set Windows Form Always on Top of Other Applications in VB6

How to Minimize/Send an App Icon to System Tray in Visual Basic 6