Click to Rate and Give Feedback
MSDN
MSDN Library
Security
Authorization
 DuplicateToken Function

  Switch on low bandwidth view
DuplicateToken Function

The DuplicateToken function creates a new access token that duplicates one already in existence.

Syntax

C++
BOOL WINAPI DuplicateToken(
  __in   HANDLE ExistingTokenHandle,
  __in   SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
  __out  PHANDLE DuplicateTokenHandle
);

Parameters

ExistingTokenHandle [in]

A handle to an access token opened with TOKEN_DUPLICATE access.

ImpersonationLevel [in]

Specifies a SECURITY_IMPERSONATION_LEVEL enumerated type that supplies the impersonation level of the new token.

DuplicateTokenHandle [out]

A pointer to a variable that receives a handle to the duplicate token. This handle has TOKEN_IMPERSONATE and TOKEN_QUERY access to the new token.

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

Return Value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

The DuplicateToken function creates an impersonation token, which you can use in functions such as SetThreadToken and ImpersonateLoggedOnUser. The token created by DuplicateToken cannot be used in the CreateProcessAsUser function, which requires a primary token. To create a token that you can pass to CreateProcessAsUser, use the DuplicateTokenEx function.

Requirements

Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinbase.h (include Windows.h)
LibraryAdvapi32.lib
DLLAdvapi32.dll

See Also

Access Control Overview
Basic Access Control Functions
CreateProcessAsUser
DuplicateTokenEx
ImpersonateLoggedOnUser
SECURITY_IMPERSONATION_LEVEL
SetThreadToken

Send comments about this topic to Microsoft

Build date: 6/26/2009

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker