I have very common bug while call WTSQueryUserToken()
. It returns false and GetLastError()
show me ERROR_PRIVILEGE_NOT_HELD
.
I tried set privileges(return OK) but i see same problem calling WTSQueryUserToken.
LUID luid;
bRet = LookupPrivilegeValue(NULL, SE_TCB_NAME, &luid);
if (!bRet) {
hr = GetLastError();
return hr;
}
TOKEN_PRIVILEGES adjTokenPrivileges;// = { 0 };
adjTokenPrivileges.PrivilegeCount = 1;
adjTokenPrivileges.Privileges[0].Luid = luid;
adjTokenPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
//CSampleCredential::Log("AdjustTokenPrivileges...");
DWORD dwOldTPLen;
bRet = AdjustTokenPrivileges(processToken, FALSE, &adjTokenPrivileges, sizeof(TOKEN_PRIVILEGES), &oldTokenPrivileges, &dwOldTPLen);
if (bRet) {
hr = GetLastError();
if (hr == ERROR_SUCCESS);
else if (hr == ERROR_NOT_ALL_ASSIGNED) {
// Enabled by default
}
}
else {
hr = GetLastError();
return hr;
}
//CSampleCredential::Log("WTSGetActiveConsoleSessionId...");
DWORD conSessId = WTSGetActiveConsoleSessionId();
if (conSessId == 0xFFFFFFFF) {
// There is no session attached to the console
return ERROR_SUCCESS;
}
//impersonationToken = GetCurrentUserToken();
//CSampleCredential::Log("WTSQueryUserToken...");
bRet = WTSQueryUserToken(conSessId, &impersonationToken);
if (!bRet) {
hr = GetLastError();
return hr;
}
Privileges for service also ok
OS: Windows 7 64
User contributions licensed under CC BY-SA 3.0