> For the complete documentation index, see [llms.txt](https://www.pinvoke.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.pinvoke.dev/advapi32/duplicatetokenex.md).

# DuplicateTokenEx

```csharp
[DllImport("ADVAPI32.dll", ExactSpelling = true, SetLastError = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern unsafe BOOL DuplicateTokenEx(
    HANDLE hExistingToken,
    TOKEN_ACCESS_MASK dwDesiredAccess,
    [Optional] SECURITY_ATTRIBUTES* lpTokenAttributes,
    SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
    TOKEN_TYPE TokenType,
    HANDLE* phNewToken);
```

[TOKEN\_ACCESS\_MASK](/security/token_access_mask.md)

[SECURITY\_IMPERSONATION\_LEVEL](/security/security_impersonation_level.md)

[TOKEN\_TYPE](/security/token_type.md)
