Guest User

Untitled

a guest
Dec 13th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. bool SetProcessSEPrivilege(HANDLE process, PrivilegeOption option)
  2. {
  3. DWORD flags = TOKEN_ADJUST_PRIVILEGES;
  4. base::win::ScopedHandle token;
  5. if (!OpenProcessToken(process, flags, token.Receive()))
  6. {
  7. return false;
  8. }
  9.  
  10. LUID uid;
  11. if (!LookupPrivilegeValueW(nullptr, SE_DEBUG_NAME, &uid))
  12. {
  13. return false;
  14. }
  15.  
  16. TOKEN_PRIVILEGES tp;
  17. tp.PrivilegeCount = 1;
  18. tp.Privileges[0].Luid = uid;
  19. tp.Privileges[0].Attributes = (option == PrivilegeOption::ENABLE) ? SE_PRIVILEGE_ENABLED : 0;
  20. BOOL rv = AdjustTokenPrivileges(token.Get(), FALSE, &tp, sizeof(tp), nullptr, nullptr);
  21. return !!rv;
  22. }
Add Comment
Please, Sign In to add comment