bool elevateProcessPrivilege()
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// Get a token for this process.
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
return false;
// Get the LUID for the privilege we want to enable.
if (!LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tkp.Privileges[0].Luid))
return false;
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Enable the privilege in the access token.
if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, NULL))
return false;
if (GetLastError() == ERROR_NOT_ALL_ASSIGNED)
return false;
return true;
}