Function Reference


WinGetProcess

Retrieves the Process ID (PID) associated with a window.

WinGetProcess ( "title" [, "text"] )

Parameters

title The title/hWnd/class of the window to get the PID. See Title special definition.
text [optional] The text of the window to get the PID. Default is an empty string. See Text special definition.

Return Value

Success: a process ID (PID).
Failure: -1 if the window is not found.

Related

ProcessList, ProcessWait, ProcessWaitClose

Example

#include <MsgBoxConstants.au3>

Example()

Func Example()
        ; Run Notepad
        Run("notepad.exe")

        ; Wait 10 seconds for the Notepad window to appear.
        Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)

        ; Retrieve the PID of Notepad using the window handle returned by WinWait.
        Local $iPID = WinGetProcess($hWnd)

        ; Display the PID of the window.
        MsgBox($MB_SYSTEMMODAL, "", "The PID is: " & $iPID)

        ; Close the Notepad window using the handle returned by WinWait.
        WinClose($hWnd)
EndFunc   ;==>Example