Don't mean to necro-post, but I was cleaning out my documents folders and found something relevant to this thread, and I wanted to add a thread pointer to the guide's index for this topic.
Code:
bool SetDebugPrivileges() {
LUID Luid;
TOKEN_PRIVILEGES tpToken;
HANDLE hToken;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, &hToken)) {
return false;
}
if (!LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &Luid)) {
CloseHandle (hToken);
return false;
}
tpToken.PrivilegeCount = 1;
tpToken.Privileges[0].Luid = Luid;
tpToken.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if (!AdjustTokenPrivileges(hToken, false, &tpToken, NULL, NULL, NULL)) {
CloseHandle(hToken);
return false;
}
CloseHandle(hToken);
return true;
}