ZwDuplicateObject

ZwDuplicateObject routine

The ZwDuplicateObject routine creates a handle that is a duplicate of the specified source handle.

Syntax


NTSTATUS ZwDuplicateObject(
  _In_      HANDLE      SourceProcessHandle,
  _In_      HANDLE      SourceHandle,
  _In_opt_  HANDLE      TargetProcessHandle,
  _Out_opt_ PHANDLE     TargetHandle,
  _In_      ACCESS_MASK DesiredAccess,
  _In_      ULONG       HandleAttributes,
  _In_      ULONG       Options
);

Parameters

SourceProcessHandle [in]

A handle to the source process for the handle being duplicated.

SourceHandle [in]

The handle to duplicate.

TargetProcessHandle [in, optional]

A handle to the target process that is to receive the new handle. This parameter is optional and can be specified as NULL if the DUPLICATE_CLOSE_SOURCE flag is set in Options.

TargetHandle [out, optional]

A pointer to a HANDLE variable into which the routine writes the new duplicated handle. The duplicated handle is valid in the specified target process. This parameter is optional and can be specified as NULL if no duplicate handle is to be created.

DesiredAccess [in]

An ACCESS_MASK value that specifies the desired access for the new handle.

HandleAttributes [in]

A ULONG that specifies the desired attributes for the new handle. For more information about attributes, see the description of the Attributes member in OBJECT_ATTRIBUTES.

Options [in]

A set of flags to control the behavior of the duplication operation. Set this parameter to zero or to the bitwise OR of one or more of the following flags.

Flag nameDescription
DUPLICATE_SAME_ATTRIBUTESInstead of using the HandleAttributes parameter, copy the attributes from the source handle to the target handle.
DUPLICATE_SAME_ACCESSInstead of using the DesiredAccess parameter, copy the access rights from the source handle to the target handle.
DUPLICATE_CLOSE_SOURCEClose the source handle.

 

Return value

ZwDuplicateObject returns STATUS_SUCCESS if the call is successful. Otherwise, it returns an appropriate error status code.

Remarks

The source handle is evaluated in the context of the specified source process. The calling process must have PROCESS_DUP_HANDLE access to the source process. The duplicate handle is created in the handle table of the specified target process. The calling process must have PROCESS_DUP_HANDLE access to the target process.

By default, the duplicate handle is created with the attributes specified by the HandleAttributes parameter, and with the access rights specified by the DesiredAccess parameter. If necessary, the caller can override one or both defaults by setting the DUPLICATE_SAME_ATTRIBUTES and DUPLICATE_SAME_ACCESS flags in the Options parameter.

If the call to this function occurs in user mode, you should use the name "NtDuplicateObject" instead of "ZwDuplicateObject".

Requirements

Target platform

Universal

Version

Available starting with Windows 2000.

Header

Ntifs.h (include Ntdef.h, Ntifs.h, or Fltkernel.h)

Library

Ntoskrnl.lib

IRQL

PASSIVE_LEVEL

See also

ACCESS_MASK
OBJECT_ATTRIBUTES

 

 

Send comments about this topic to Microsoft

Show:
© 2016 Microsoft