.exe mittels Fenstername finden

  • Hallo,

    Kann mir jemand sagen wie ich herausfinden kann wo die .exe liegt die ein Fenster erzeugt? Also wie ich z.B. herausfinden kann mittels des Fensternamens 'iTunes' wo meine 'iTunes.exe' liegt? Gibt es da eine Möglichkeit? Manuell kann man das machen über den Taskmanager (Unter 'Anwendungen' rechtsklick auf das gewünschte Fenster und dann 'Zu Prozess wechseln', und dann auf den makierten Prozess rechtklick und dann 'Dateipfad öffnen'), kann man das mit AutoIt nachbauen?


    Vielen Dank fürs Lesen, drüber nach Grübeln und Beantworten!!

  • Spoiler anzeigen
    [autoit]

    #include <winapi.au3>
    Opt("WinTitleMatchMode", 2)

    [/autoit] [autoit][/autoit] [autoit]

    $Title = "Mozilla Firefox"

    [/autoit] [autoit][/autoit] [autoit]

    $Pid = WinGetProcess(WinGetTitle($Title))
    $Path = _GetPathByPID($Pid)

    [/autoit] [autoit][/autoit] [autoit]

    MsgBox(0, "", $Path)

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ; 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])
    ;===============================================================================

    [/autoit] [autoit][/autoit] [autoit]

    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*", 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

    [/autoit]