devxlogo

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

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist