#Include <WinAPIEx.au3>
Opt('MustDeclareVars', 1)
If _WinAPI_GetVersion() < '6.0' Then
MsgBox(16, 'Error', 'Require Windows Vista or later.')
Exit
EndIf
Global $ID = ProcessExists('explorer.exe')
If $ID Then
ConsoleWrite(_WinAPI_GetProcessFileNameEx($ID) & @CR)
EndIf
; #FUNCTION# ====================================================================================================================
; Name...........: _WinAPI_GetProcessFileNameEx
; Description....: Retrieves the fully-qualified path to the executable file for the specified 32-bit or 64-bit process.
; Syntax.........: _WinAPI_GetProcessFileNameEx ( [$PID] )
; Parameters.....: $PID - The PID of the process. Default (0) is the current process.
; Return values..: Success - The fully-qualified path to the executable file.
; Failure - Empty string and sets the @error flag to non-zero.
; Author.........: Yashied
; Modified.......:
; Remarks........: This function requires Windows Vista or later.
; Related........:
; Link...........: @@MsdnLink@@ QueryFullProcessImageName
; Example........: Yes
; ===============================================================================================================================
Func _WinAPI_GetProcessFileNameEx($PID = 0)
If Not $PID Then
$PID = @AutoItPID
EndIf
Local $hProcess = DllCall('kernel32.dll', 'ptr', 'OpenProcess', 'dword', __Iif($__WINVER < 0x0600, 0x00000400, 0x00001000), 'int', 0, 'dword', $PID)
If (@error) Or (Not $hProcess[0]) Then
Return SetError(1, 0, '')
EndIf
Local $Path = _WinAPI_QueryFullProcessImageName($hProcess[0])
_WinAPI_CloseHandle($hProcess[0])
If Not $Path Then
Return SetError(1, 0, '')
EndIf
Return $Path
EndFunc ;==>_WinAPI_GetProcessFileNameEx
; #FUNCTION# ====================================================================================================================
; Name...........: _WinAPI_QueryFullProcessImageName
; Description....: Retrieves the full name of the executable image for the specified process.
; Syntax.........: _WinAPI_QueryFullProcessImageName ( $hProcess )
; Parameters.....: $hProcess - A handle to the process. The handle must have the $PROCESS_QUERY_INFORMATION or
; $PROCESS_QUERY_LIMITED_INFORMATION access right.
; Return values..: Success - The fully-qualified path to the module.
; Failure - Empty string and sets the @error flag to non-zero.
; Author.........: Yashied
; Modified.......:
; Remarks........: This function requires Windows Vista or later.
; Related........:
; Link...........: @@MsdnLink@@ QueryFullProcessImageName
; Example........: Yes
; ===============================================================================================================================
Func _WinAPI_QueryFullProcessImageName($hProcess)
Local $Ret = DllCall('kernel32.dll', 'int', 'QueryFullProcessImageNameW', 'ptr', $hProcess, 'dword', 0, 'wstr', '', 'dword*', 4096)
If (@error) Or (Not $Ret[0]) Then
Return SetError(1, 0, '')
EndIf
Return $Ret[3]
EndFunc ;==>_WinAPI_QueryFullProcessImageName