我在通话时遇到了非常常见的错误WTSQueryUserToken()
。它返回 false 并GetLastError()
显示给我ERROR_PRIVILEGE_NOT_HELD
。我尝试了设置权限(返回 OK),但我看到调用 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;
}
服务特权还可以
操作系统:Windows 7 64