- Offizieller Beitrag
Hi,
hier mal eine Möglichkeit mit der PID den Pfad der Anwendung zu ermitteln.
Wird keine PID übergeben, gibt die Funktion den Pfad für die Anwendung des aktiven Fensters zurück.
_GetPathByPID()
; Wenn keine PID übergeben, wird der Pfad der aktuellen Anwendung anhand der PID ermittelt
ConsoleWrite(_GetPathByPID() & @CRLF)
;===============================================================================
; Function Name: _GetPathByPID($PID=-1)
; Description:: Get full path of an running application by using PID
; Parameter(s): $PID - PID, if not set will used PID from active Window
; Requirement(s): #include <WinAPI.au3>
; Return Value(s): Success Full ApplicationPath
; Failure set @error 1 - process handle failed
; 2 - process image failed
; 3 - query dosdevice failed
; Author(s): BugFix ([email='bugfix@autoit.de'][/email])
;===============================================================================
#include-once
#include <WinAPI.au3>
Func _GetPathByPID($PID=-1)
If $PID = -1 Then $PID = WinGetProcess(WinGetTitle("[active]"))
$hProcess = _WinAPI_OpenProcess(0x00000400, True, $PID, True)
If Not $hProcess Then Return SetError(1,0,0)
Local $ret, $path, $DevicePath, $DeviceLetter, $strPath = DllStructCreate("char path[256]")
DllCall(@SystemDir & '\Psapi.dll', "uint64", "GetProcessImageFileNameA", _
"hwnd", $hProcess, "ptr", DllStructGetPtr($strPath), "int", 256)
If @error Then Return SetError(2,0,0)
$path = DllStructGetData($strPath, 'path')
$DevicePath = StringRegExp($path, "\\Device\\\w*\\[\w\d\+\-()]*", 1)
Local $lpTargetPath, $aDrive = DriveGetDrive("ALL")
For $i = 1 To UBound($aDrive) -1
$ret = DllCall("kernel32.dll", "long", "QueryDosDeviceA", "str", $aDrive[$i], "str", $lpTargetPath, "long", 256)
If @error Then Return SetError(3,0,0)
If $ret[2] = $DevicePath[0] Then
$DeviceLetter = $aDrive[$i]
ExitLoop
EndIf
Next
DllCall("kernel32.dll", "long", "CloseHandle", "long", $hProcess)
Return StringReplace($path, $DevicePath[0], StringUpper($DeviceLetter))
EndFunc ;==>_GetPathByPID
Edit: Es gibt ja kaum was, was nicht schon jemand getan hat
Habe gerade eine ähnliche Lösung (1 Monat alt) im EN-Forum gefunden. Link
Naja, ich habs als Zweiter getan - der andere als Vorletzter.