What I'm trying to achieve is the actual Token handle from the session ID when the process runs as admin under non admin user(windows logged in user).
DWORD dwSessionId = 0;
if (false == ProcessIdToSessionId(dwProcessId, &dwSessionId))
{
LOG_ERROR(L"Failed obtaining session id");
return false;
}
HANDLE hToken
if (false == WTSQueryUserToken(dwSessionId, &hToken))
{
LOG_ERROR(L"Failed to obtain session's handle");
return false;
}
My problem occurs when i call WTSQueryUserToken, it fails with error 1314 which means i need to grant the calling token with a SE_TCB_NAME privilege.
so i tried doing so with the following code:
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
bool bSuccess = DynamicAPI::AdjustTokenPrivileges(
%%WHICH_TOKEN_EXACTLLY%%,
FALSE,
&tp,
sizeof(TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES)nullptr,
(DWORD)nullptr);
But I'm not entirely sure which token should be provided exactly. I have marked it with %%WHICH_TOKEN_EXACTLLY%% placeholder. For my tests i tried to AdjustTokenPriviliges my process' token(administrator's privileges), but it didn't help either.