# Function Reference

# _WinAPI_DuplicateHandle

Duplicates an object handle

#include <WinAPIHObj.au3>
_WinAPI_DuplicateHandle ( $hSourceProcessHandle, $hSourceHandle, $hTargetProcessHandle, $iDesiredAccess, $iInheritHandle, $iOptions )

## Parameters

$hSourceProcessHandle | A handle to the process with the handle to be duplicated
$hSourceHandle | The handle to be duplicated
$hTargetProcessHandle | A handle to the process that is to receive the duplicated handle
$iDesiredAccess | The access requested for the new handle
$iInheritHandle | A variable that indicates whether the handle is inheritable
$iOptions | Optional actions

## Return Value

Success: | New handle
Failure: | 0, call _WinAPI_GetLastError() to get extended error information

## Related

_WinAPI_CloseHandle, _WinAPI_OpenProcess

## See Also

Search DuplicateHandle in MSDN Library.

## Example

    #include <WinAPIHObj.au3>

    Local $hCurProcessPseudo = _WinAPI_GetCurrentProcess()
    ConsoleWrite("Pseudo handle for current process = " & $hCurProcessPseudo & @CRLF)

    Local $hCurProcess = _WinAPI_DuplicateHandle($hCurProcessPseudo, $hCurProcessPseudo, $hCurProcessPseudo, Default, True, $DUPLICATE_SAME_ACCESS)
    ConsoleWrite("Real handle for current process = " & $hCurProcess & @CRLF)

    ; ...

    ; Close handle when no longer needed
    _WinAPI_CloseHandle($hCurProcess)