#ifndef _NTRTL_H
NTSYSAPI
NTSTATUS
NTAPI
RtlImpersonateSelf(
_In_ SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
);
View code on GitHubImpersonates a copy of the current process's token on the current thread.
ImpersonationLevel - the impersonation level to use.The function opens the current process token via NtOpenProcessTokenEx, duplicates it via NtDuplicateToken, and then impersonates it via NtSetInformationThread with ThreadImpersonationToken.
To reset impersonation, use NtSetInformationThread with ThreadImpersonationToken info class and a NULL token handle.