Home  |  About  |   Search   

What's New
Table Of Contents
Credits
Netiquette
10 Commandments 
Bugs
Tables
Queries
Forms
Reports
Modules
APIs
Strings
Date/Time
General
Downloads
Resources
Search
Feedback
mvps.org

RunCommand Constants

Terms of Use


 

API: Find the associated EXE file

Author(s)
Dev Ashish

(Q)    How can I find out the complete path to an executable?

(A)    Pass the filename (not the exe file, but the document file) and its location to this function.

'*********** Code Start ************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Const cMAX_PATH = 260
Const ERROR_NOASSOC = 31
Const ERROR_FILE_NOT_FOUND = 2&
Const ERROR_PATH_NOT_FOUND = 3&
Const ERROR_BAD_FORMAT = 11&
Const ERROR_OUT_OF_MEM = 0

Private Declare Function apiFindExecutable Lib "shell32.dll" _
    Alias "FindExecutableA" _
    (ByVal lpFile As String, _
    ByVal lpDirectory As String, _
    ByVal lpResult As String) _
    As Long
    
Function fFindEXE(stFile As String, _
                    stDir As String) _
                    As String
'Usage Example:
'   ?fFindEXE("test.xls","c:\temp")
'
Dim lpResult As String
Dim lngRet As Long

    lpResult = Space(cMAX_PATH)
    lngRet = apiFindExecutable(stFile, stDir, lpResult)
    
    If lngRet > 32 Then
        fFindEXE = lpResult
    Else
        Select Case lngRet:
            Case ERROR_NOASSOC: fFindEXE = "Error: No Association"
            Case ERROR_FILE_NOT_FOUND: fFindEXE = "Error: File Not Found"
            Case ERROR_PATH_NOT_FOUND: fFindEXE = "Error: Path Not Found"
            Case ERROR_BAD_FORMAT:  fFindEXE = "Error: Bad File Format"
            Case ERROR_OUT_OF_MEM:  fFindEXE = "Error: Out of Memory"
        End Select
    End If
End Function

'*********** Code End ************

1998-2009, Dev Ashish & Arvin Meyer, All rights reserved. Optimized for Microsoft Internet Explorer