AdvApi32DuplicateTokenEx Method
Creates a new access token that duplicates an existing token.
This function can create either a primary token or an impersonation token.
Namespace: DevCase.Win32.NativeMethodsAssembly: 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 Shared Function DuplicateTokenEx (
existingToken As IntPtr,
desiredAccess As TokenAccess,
tokenAttributes As SecurityAttributes,
impersonationLevel As SecurityImpersonationLevel,
tokenType As TokenType,
<OutAttribute> ByRef refNewToken As IntPtr
) As Boolean
Dim existingToken As IntPtr
Dim desiredAccess As TokenAccess
Dim tokenAttributes As SecurityAttributes
Dim impersonationLevel As SecurityImpersonationLevel
Dim tokenType As TokenType
Dim refNewToken As IntPtr
Dim returnValue As Boolean
returnValue = AdvApi32.DuplicateTokenEx(existingToken,
desiredAccess, tokenAttributes,
impersonationLevel, tokenType, refNewToken)
No code example is currently available or this language may not be supported.
- 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.
Boolean
If the function succeeds, the return value is
.
If the function fails, the return value is
.
To get extended error information, call
GetLastWin32Error.