| Store | Cart

ActiveState Docs

ActivePython 2.5 Documentation

Loading...

win32api.DuplicateHandle

PyHANDLE = DuplicateHandle(hSourceProcess, hSource , hTargetProcessHandle , desiredAccess , bInheritHandle , options )

Duplicates a handle.

Parameters

hSourceProcess : PyHANDLE

Identifies the process containing the handle to duplicate.

hSource : PyHANDLE

Identifies the handle to duplicate. This is an open object handle that is valid in the context of the source process.

hTargetProcessHandle : PyHANDLE

Identifies the process that is to receive the duplicated handle. The handle must have PROCESS_DUP_HANDLE access.

desiredAccess : int

Specifies the access requested for the new handle. This parameter is ignored if the dwOptions parameter specifies the DUPLICATE_SAME_ACCESS flag. Otherwise, the flags that can be specified depend on the type of object whose handle is being duplicated. For the flags that can be specified for each object type, see the following Remarks section. Note that the new handle can have more access than the original handle.

bInheritHandle : int

Indicates whether the handle is inheritable. If TRUE, the duplicate handle can be inherited by new processes created by the target process. If FALSE, the new handle cannot be inherited.

options : int

Specifies optional actions. This parameter can be zero, or any combination of the following flags

DUPLICATE_CLOSE_SOURCEloses the source handle. This occurs regardless of any error status returned. DUPLICATE_SAME_ACCESSIgnores the dwDesiredAccess parameter. The duplicate handle has the same access as the source handle.

Comments

When duplicating a handle for a different process, you should either keep a reference to the returned PyHANDLE, or call .Detach() on it to prevent it from being closed prematurely.