Created
December 13, 2018 08:32
-
-
Save kingsamchen/0769f66a0fd28cefe3643783e478b03f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool SetProcessSEPrivilege(HANDLE process, PrivilegeOption option) | |
{ | |
DWORD flags = TOKEN_ADJUST_PRIVILEGES; | |
base::win::ScopedHandle token; | |
if (!OpenProcessToken(process, flags, token.Receive())) | |
{ | |
return false; | |
} | |
LUID uid; | |
if (!LookupPrivilegeValueW(nullptr, SE_DEBUG_NAME, &uid)) | |
{ | |
return false; | |
} | |
TOKEN_PRIVILEGES tp; | |
tp.PrivilegeCount = 1; | |
tp.Privileges[0].Luid = uid; | |
tp.Privileges[0].Attributes = (option == PrivilegeOption::ENABLE) ? SE_PRIVILEGE_ENABLED : 0; | |
BOOL rv = AdjustTokenPrivileges(token.Get(), FALSE, &tp, sizeof(tp), nullptr, nullptr); | |
return !!rv; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment