Make your own free website on

Launch File With His Associate Program

'This example will show you how to launch a file with his associate program.
'It will do the same action that occur when you Double Click on the file.
'For Example, if when you double click on mp3 file it launch with Winamp,
'This code will do the same.
'Add a module to your project (In the menu choose Project -> Add Module, Then click Open)
'Insert this code to the module :

#If Win32 Then
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
Declare Function GetDesktopWindow Lib "user32" () As Long
Declare Function ShellExecute Lib "SHELL" (ByVal hwnd%, _
ByVal lpszOp$, ByVal lpszFile$, ByVal lpszParams$, _
ByVal lpszDir$, ByVal fsShowCmd%) As Integer
Declare Function GetDesktopWindow Lib "USER" () As Integer
#End If
Public Const SW_SHOWNORMAL = 1

'Insert this code to your form:

Function StartDoc(DocName As String) As Long
Dim Scr_hDC As Long
Scr_hDC = GetDesktopWindow()
StartDoc = ShellExecute(Scr_hDC, "Open", DocName, "", "C:\", SW_SHOWNORMAL)
End Function

Private Sub Form_Load()
Dim r As Long
'Replace the c:\mp3\song.mp3 with the file you want to launch
r = StartDoc("c:\mp3\song.mp3")
End Sub

Go Back