Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long
Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Function GetExePathFileFromExtention(ByVal sExtension As String) As String
Dim sPath As String, lRet As Long, sBuffer As String, FF As Integer
' on récupère le chemin TEMP
sBuffer = String$(512, vbNullChar)
lRet = GetTempPath(512, sBuffer)
sPath = Left$(sBuffer, lRet)
If Not (RightB$(sPath, 2) = "\") Then sPath = sPath & "\"
' on crée un fichier temporaire
sPath = sPath & Format$(Now, "MMDDHHNNSS") & "." & sExtension
FF = FreeFile
Open sPath For Output As #FF
Print #FF, vbNullString
Close #FF
' on récupère l'exe associé
sBuffer = String$(260, vbNullChar)
lRet = FindExecutable(sPath, vbNullString, sBuffer)
' retour
If lRet > 32 Then
GetExePathFileFromExtention = Left$(sBuffer, InStr(sBuffer, vbNullChar) - 1)
Else
GetExePathFileFromExtention = vbNullString
End If
' supprime fichier temp
Call DeleteFile(sPath)
End Function