+ dwErrorCode = GetLastError();
+ ERR("GetTokenInformation failed with error %lu!\n", dwErrorCode);
+ goto Cleanup;
+ }
+
+ // Check if this is an impersonation token and only set it as the thread token in this case.
+ // This is not always an impersonation token, see RevertToPrinterSelf.
+ if (Type == TokenImpersonation)
+ {
+ if (!SetThreadToken(NULL, hToken))
+ {
+ dwErrorCode = GetLastError();
+ ERR("SetThreadToken failed with error %lu!\n", dwErrorCode);
+ goto Cleanup;
+ }