The ImpersonateLoggedOnUser function lets the calling thread impersonate a user. The user is represented by a token handle.
BOOL ImpersonateLoggedOnUser(
HANDLE hToken |
// handle to a token that represents a logged-on user |
); |
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.
The impersonation lasts until the thread exits or until it calls RevertToSelf.
The calling thread does not need to have any particular privileges to call ImpersonateLoggedOnUser.
CreateProcessAsUser, DuplicateToken, DuplicateTokenEx, LogonUser, OpenProcessToken, or OpenThreadToken, RevertToSelf