| 2 | #include "trustinstaller_utils.h" |
| 3 | |
| 4 | void Elevate::EnablePrivilege(std::wstring privilegeName) |
| 5 | { |
| 6 | HANDLE hToken; |
| 7 | if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, &hToken)) |
| 8 | throw std::runtime_error("OpenProcessToken failed: " + std::to_string(GetLastError())); |
| 9 | |
| 10 | LUID luid; |
| 11 | if (!LookupPrivilegeValueW(nullptr, privilegeName.c_str(), &luid)) |
| 12 | { |
| 13 | CloseHandle(hToken); |
| 14 | throw std::runtime_error("LookupPrivilegeValue failed: " + std::to_string(GetLastError())); |
| 15 | } |
| 16 | |
| 17 | TOKEN_PRIVILEGES tp; |
| 18 | tp.PrivilegeCount = 1; |
| 19 | tp.Privileges[0].Luid = luid; |
| 20 | tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; |
| 21 | if (!AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), nullptr, nullptr)) |
| 22 | { |
| 23 | CloseHandle(hToken); |
| 24 | throw std::runtime_error("AdjustTokenPrivilege failed: " + std::to_string(GetLastError())); |
| 25 | } |
| 26 | |
| 27 | CloseHandle(hToken); |
| 28 | } |
| 29 | |
| 30 | DWORD Elevate::GetProcessIdByName(std::wstring processName) |
| 31 | { |
nothing calls this directly
no outgoing calls
no test coverage detected