You are sure you explicitly run your application with administrative rights?
And did you ever check if a function inside your SetDebugPrivilege() function fails?
Exceptions are a nice way to cover this. I do it like this in my lib:
Code:
void Process::AddLocalDebugPrivileges_() const
{
HANDLE hToken;
SafeHandle ensureClosure(hToken);
if(!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
throw std::runtime_error("Process::AddLocalDebugPrivileges_ Error : OpenProcessToken() failed");
TOKEN_PRIVILEGES tp;
if(!LookupPrivilegeValueA(NULL, "SeDebugPrivilege", &tp.Privileges[0].Luid))
throw std::runtime_error("Process::AddLocalDebugPrivileges_ Error : LookupPrivilegeValueA() failed");
tp.PrivilegeCount = 1;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if(!AdjustTokenPrivileges(hToken, FALSE, &tp, 0, (PTOKEN_PRIVILEGES)NULL, 0))
throw std::runtime_error("Process::AddLocalDebugPrivileges_ Error : AdjustTokenPrivileges() failed");
}