Function Reference


_WinAPI_OpenProcess

Returns a handle of an existing process object

#include <WinAPIProc.au3>
_WinAPI_OpenProcess ( $iAccess, $bInherit, $iPID [, $bDebugPriv = False] )

Parameters

$iAccess Specifies the access to the process object
$bInherit Specifies whether the returned handle can be inherited
$iPID Specifies the process identifier of the process to open
$bDebugPriv [optional] Certain system processes can not be opened unless you have the debug security privilege.
If True, this function will attempt to open the process with debug privileges if the process can not be opened with standard access privileges.

Return Value

Success: the process handle to the object.
Failure: sets the @error flag to non-zero.

Related

_WinAPI_CloseHandle, _WinAPI_ReadProcessMemory, _WinAPI_WriteProcessMemory

See Also

Search OpenProcess in MSDN Library.

Example

#include <ProcessConstants.au3>
#include <WinAPIHObj.au3>
#include <WinAPIProc.au3>
#include <WinAPISys.au3>

; _WinAPI_CreateProcess() will be the best solution
Local $iPID = Run('cmd.exe /k')
If Not $iPID Then
        Exit
EndIf

; Note, immediately open the process
Local $hProcess
If Number(_WinAPI_GetVersion()) >= 6.0 Then
        $hProcess = _WinAPI_OpenProcess($PROCESS_QUERY_LIMITED_INFORMATION, 0, $iPID)
Else
        $hProcess = _WinAPI_OpenProcess($PROCESS_QUERY_INFORMATION, 0, $iPID)
EndIf
If Not $hProcess Then
        Exit
EndIf

; Wait until the process exists, try enter "exit 6"
While ProcessExists($iPID)
        Sleep(100)
WEnd

ConsoleWrite('Exit code: ' & _WinAPI_GetExitCodeProcess($hProcess) & @CRLF)

_WinAPI_CloseHandle($hProcess)