Note that there are some explanatory texts on larger screens.

plurals
  1. POAdjustTokenPrivileges error 6 - handle invalid
    text
    copied!<p>Please advise why the <code>AdjustTokenPrivileges</code> function below always returns true, thus giving: "AdjustTokenPrivileges error 6" (ie invalid handle)?</p> <p>stackoverlow is complaining that I didn't explain this enough</p> <p>I don't know what else to add. I'm new to c++.</p> <pre><code>HANDLE hToken; OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES, &amp;hToken); SetPrivilege(hToken,L"SeBackupPrivilege",1 ); CloseHandle(hToken); </code></pre> <hr> <pre><code>BOOL SetPrivilege( HANDLE hToken, // access token handle LPCTSTR lpszPrivilege, // name of privilege to enable/disable BOOL bEnablePrivilege // to enable or disable privilege ) { TOKEN_PRIVILEGES oldtp; /* old token privileges */ TOKEN_PRIVILEGES tp; DWORD dwSize = sizeof (TOKEN_PRIVILEGES); LUID luid; if ( !LookupPrivilegeValue( NULL, // lookup privilege on local system lpszPrivilege, // privilege to lookup &amp;luid ) ) // receives LUID of privilege { printf("LookupPrivilegeValue error: %u\n", GetLastError() ); return FALSE; } tp.PrivilegeCount = 1; tp.Privileges[0].Luid = luid; if (bEnablePrivilege) tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; else tp.Privileges[0].Attributes = 0; // Enable the privilege or disable all privileges. if ( !AdjustTokenPrivileges( &amp;hToken, FALSE, &amp;tp, sizeof(TOKEN_PRIVILEGES), (PTOKEN_PRIVILEGES) &amp;oldtp, (PDWORD) &amp;dwSize) ) { printf("AdjustTokenPrivileges error: %u\n", GetLastError() ); //Get error 6 here (ie invalid handle) return FALSE; } if (GetLastError() == ERROR_NOT_ALL_ASSIGNED) { printf("The token does not have the specified privilege. \n"); return FALSE; } return TRUE; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload