Advanced Files & Folders

Default Programs

It is quite simple to open a file using its default program (for example, if you double click a *.doc file in explorer, Word will automatically load. You do this using the ShellExecute function. This also allows you to open a browser with the specified URL, or an write a new email, to the specified email address:

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

'// open file (quotes are used so that the actual value that is passed is "C: est.doc"
Private Sub cmdOpen_Click()
    If ShellExecute(0, vbNullString, """"C: est.doc"""", vbNullString, vbNullString, vbNormalFocus) = 2 Then
End Sub

'// open url
Private Sub cmdOpen_Click()
    If ShellExecute(0, vbNullString, "http://www.vbweb.f9.co.uk/", vbNullString, vbNullString, vbNormalFocus) = 2 Then
End Sub

'// open email address
Private Sub cmdOpen_Click()
    If ShellExecute(0, vbNullString, "mailto:support@vbweb.f9.co.uk", vbNullString, vbNullString, vbNormalFocus) = 2 Then
End Sub

You might also like...

Comments

About the author

James Crowley

James Crowley United Kingdom

James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Java is to JavaScript what Car is to Carpet.” - Chris Heilmann