GetExecutableFile – Find the program associated to a document file

Private Declare Function FindExecutable Lib "shell32.dll" Alias _    "FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As String, _    ByVal sResult As String) As LongPrivate Const MAX_PATH = 260Private Const ERROR_FILE_NO_ASSOCIATION = 31&Private Const ERROR_FILE_NOT_FOUND = 2&Private Const ERROR_PATH_NOT_FOUND = 3&Private Const ERROR_FILE_SUCCESS = 32&' Return the name and path of the EXEcutable file that' is associated to the specified file.' Returns a null string if there is no such associated file,' and raises an error if the file or the path hasn't been found.Public Function GetExecutableFile(ByVal FileName As String) As String    Dim sPath As String, sFile As String    Dim lPos As Long    Dim sResult As String    ' get the file's name and path, exit if no path is there    lPos = InStrRev(FileName, "")    If lPos = 0 Then Exit Function    sPath = Left$(FileName, lPos)    sFile = Mid$(FileName, lPos + 1)        ' call the FindExecutable API function and    ' process the return value    sResult = Space(MAX_PATH)    Select Case FindExecutable(sFile, sPath, sResult)        Case ERROR_FILE_NOT_FOUND            Err.Raise 53     ' file not found        Case ERROR_PATH_NOT_FOUND            Err.Raise 76     ' path not found        Case ERROR_FILE_NO_ASSOCIATION            ' returns null string        Case Is >= ERROR_FILE_SUCCESS            ' extract the ANSI string that contains the            ' name of the associated executable file            GetExecutableFile = Left$(sResult, InStr(sResult & vbNullChar, _                vbNullChar) - 1)    End SelectEnd Function

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

Top 5 B2B SaaS Marketing Agencies for 2023

In recent years, the software-as-a-service (SaaS) sector has experienced exponential growth as more and more companies choose cloud-based solutions. Any SaaS company hoping to stay ahead of the curve in this quickly changing industry needs to invest in effective marketing. So selecting the best marketing agency can mean the difference

technology leadership

Why the World Needs More Technology Leadership

As a fact, technology has touched every single aspect of our lives. And there are some technology giants in today’s world which have been frequently opined to have a strong influence on recent overall technological influence. Moreover, those tech giants have popular technology leaders leading the companies toward achieving greatness.

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.