How to get required permissions for AdjustTokenPrivileges()?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello I am trying to AdjustTokenPrivileges but I keep getting ERROR_NOT_ALL_ASSIGNED error. Does anyone know what I need to do inorder to get that function below work? I even get it when i run it as system service (process runs under user SYSTEM). Do I
need to get some trusted flag to my service or what can I do if I want to get that function successfully work.<br/>
<br/>
Edit: Even requireAdministrator didnt help<br/>
<pre class="prettyprint" style=" #include <windows.h>
#include <stdio.h>
#include <Wtsapi32.h>

BOOL SetTBCPrivileges(VOID) {
DWORD dwPID;
HANDLE hProcess;
HANDLE hToken;
LUID Luid;
TOKEN_PRIVILEGES tpDebug;
dwPID = GetCurrentProcessId();
if ((hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPID)) == NULL) return FALSE;
if (OpenProcessToken(hProcess, TOKEN_ALL_ACCESS, &hToken) == 0) return FALSE;
if ((LookupPrivilegeValue(NULL, SE_TCB_NAME, &Luid)) == 0) return FALSE;
tpDebug.PrivilegeCount = 1;
tpDebug.Privileges[0].Luid = Luid;
tpDebug.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if ((AdjustTokenPrivileges(hToken, FALSE, &tpDebug, sizeof(tpDebug), NULL, NULL)) == 0) return FALSE;
printf("%Xn",GetLastError());
if (GetLastError() != ERROR_SUCCESS) return FALSE;
CloseHandle(hToken);
CloseHandle(hProcess);
return TRUE;
}

int main(){
SetTBCPrivileges();
system("pause");
return 0;
}[/code]
<br/>
<br/>

View the full article
 
Back
Top