AdvApi32DuplicateTokenEx Method

Creates a new access token that duplicates an existing token.

This function can create either a primary token or an impersonation token.

Definition

Namespace: DevCase.Win32.NativeMethods
Assembly: DevCase.net48 (in DevCase.net48.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
[DllImportAttribute("AdvApi32.dll", SetLastError = true)]
public static bool DuplicateTokenEx(
	IntPtr existingToken,
	TokenAccess desiredAccess,
	SecurityAttributes tokenAttributes,
	SecurityImpersonationLevel impersonationLevel,
	TokenType tokenType,
	out IntPtr refNewToken
)

Parameters

existingToken  IntPtr
A handle to an access token opened with Duplicate access.
desiredAccess  TokenAccess
Specifies the requested access rights for the new token.

The DuplicateTokenEx(IntPtr, TokenAccess, SecurityAttributes, SecurityImpersonationLevel, TokenType, IntPtr) function compares the requested access rights with the existing token's discretionary access control list (DACL) to determine which rights are granted or denied.

To request the same access rights as the existing token, specify zero.

To request all access rights that are valid for the caller, specify MAXIMUM_ALLOWED.

tokenAttributes  SecurityAttributes
A pointer to a SecurityAttributes structure that specifies a security descriptor for the new token and determines whether child processes can inherit the token.

If tokenAttributes is NULL, the token gets a default security descriptor and the handle cannot be inherited.

If the security descriptor contains a system access control list (SACL), the token gets ACCESS_SYSTEM_SECURITY access right, even if it was not requested in desiredAccess.

To set the owner in the security descriptor for the new token, the caller's process token must have the RestorePrivilege (SE_RESTORE_NAME) privilege set.

impersonationLevel  SecurityImpersonationLevel
The impersonation level of the new token.
tokenType  TokenType
A values that differentiate between a primary token and an impersonation token.
refNewToken  IntPtr
A pointer to a HANDLE variable that receives the new token.

When you have finished using the new token, call the CloseHandle(IntPtr) function to close the token handle.

Return Value

Boolean
If the function succeeds, the return value is .

If the function fails, the return value is .

To get extended error information, call GetLastWin32Error.

Remarks

See Also