Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void SetDebugPrivileges()
- {
- TOKEN_PRIVILEGES Debug_Privileges;
- //STEP 1
- if (!LookupPrivilegeValue (NULL, // Privieleges for the local system
- SE_DEBUG_NAME, // define the name of the privilege
- &Debug_Privileges.Privileges[0].Luid)) // will get the LUID value into this variable
- { //if function failed, cannot proceed to the next step
- return GetLastError(); //terminate the outer function
- }
- //STEP 2
- DWORD err = 0; // define error holder, used to store the error code in case of failure
- HANDLE hToken = 0; // instantiate a token handle
- if (!OpenProcessToken (GetCurrentProcess (), // current process ID handle
- TOKEN_ADJUST_PRIVILEGES, //set the desired access
- &hToken)) // handle to the token will be held here
- { // if function failed, cannot proceed to the next step
- err = GetLastError();
- if (hToken) // if handle is still valid
- CloseHandle (hToken); // destroy it
- return err; //terminate the outer function
- }
- //STEP3
- Debug_Privileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; // set to enable privilege
- Debug_Privileges.PrivilegeCount = 1; // working with only one privilege
- if (!AdjustTokenPrivileges (hToken, // access token handle
- FALSE, // do not disable privileges
- &Debug_Privileges, // pointer to the token structure
- 0, // no need for a buffer
- NULL, // previous state not set
- NULL)) // no need for a buffer
- {
- err = GetLastError();
- if (hToken) // if handle is still valid
- CloseHandle (hToken); // destroy it
- return err; //terminate the outer function
- }
- return err;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement