WTSQueryUserToken()提供ERROR_PRIVILEGE_NOT_HELD

时间:2013-05-28 10:05:25

标签: c++ windows winapi

我在呼叫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;
    }

服务权限也可以

Share photos on twitter with Twitpic

操作系统:Windows 7 64

0 个答案:

没有答案