|
APIs: Trouver le fichier EXE associé à un document |
Author(s) Dev Ashish |
|
(Q) Comment trouver le chemin exact d'un exécutable?
(A) Fournir le nom du document (pas le nom de l'exécutable),
incluant son chemin, à la fonction fFindExe.
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
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
|