Launch a File with its Associated Program

Launch a File with its Associated Program

This code will allow you to launch a file with its associated program.

 #If Win32 ThenDeclare 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 LongDeclare Function GetDesktopWindow Lib "user32" () As Long#ElseDeclare Function ShellExecute Lib "SHELL" (ByVal hwnd%, _ByVal lpszOp$, ByVal lpszFile$, ByVal lpszParams$, _ByVal lpszDir$, ByVal fsShowCmd%) As IntegerDeclare Function GetDesktopWindow Lib "USER" () As Integer#End IfPublic Const SW_SHOWNORMAL = 1Function OpenFile(sFile As String) As LongDim Scr_hDC As LongScr_hDC = GetDesktopWindow()StartDoc = ShellExecute(Scr_hDC, "Open", sFile, "", "C:", SW_SHOWNORMAL)End Function



Share the Post: