devxlogo

GetExecutableFile – Retrieving the executable associated to a file

GetExecutableFile – Retrieving the executable associated to a file

 Shared Function _    FindExecutable(ByVal fileName As String, ByVal fileDir As String, _    ByVal buffer As System.Text.StringBuilder) As IntegerEnd Function' Returns the name and path of the EXEcutable file that is associated to the ' specified file.' Returns an empty string if there is no such associated file,' and raises an error if the file or the path hasn't been found.' ' Example: Debug.WriteLine(GetExecutableFile("D:	empDb.mdb"))Public Function GetExecutableFile(ByVal filePath As String) As String    Const ERROR_FILE_NO_ASSOCIATION = 31&    Const ERROR_FILE_NOT_FOUND = 2&    Const ERROR_PATH_NOT_FOUND = 3&    Const ERROR_FILE_SUCCESS = 32&    Dim buffer As New System.Text.StringBuilder(260)    ' call the FindExecutable API function and process the return value    Select Case FindExecutable(System.IO.Path.GetFileName(filePath), _        System.IO.Path.GetDirectoryName(filePath), buffer)        Case ERROR_FILE_NOT_FOUND, ERROR_PATH_NOT_FOUND            Throw New System.IO.FileNotFoundException()        Case ERROR_FILE_NO_ASSOCIATION            Return ""        Case Is >= ERROR_FILE_SUCCESS            ' extract the ANSI string that contains the name of the associated             ' executable file            Return buffer.ToString()    End SelectEnd Function

See also  How to Create and Deploy QR Codes Online: A Comprehensive Guide
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