GetExecutableFile – Find the program associated to a document file

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:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several