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_SOURCE

loses the source handle. This occurs regardless of any error status returned.

DUPLICATE_SAME_ACCESS

Ignores 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.