#include <Windows.h>#include <iostream>int main(){ HANDLE hToken; TOKEN_PRIVILEGES tkp; if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) { std::cout << "OpenProcessToken failed with error " << GetLastError() << std::endl; return 1; } if (!LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tkp.Privileges[0].Luid)) { std::cout << "LookupPrivilegeValue failed with error " << GetLastError() << std::endl; CloseHandle(hToken); return 1; } tkp.PrivilegeCount = 1; tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) { std::cout << "AdjustTokenPrivileges failed with error " << GetLastError() << std::endl; CloseHandle(hToken); return 1; } std::cout << "Success!" << std::endl; CloseHandle(hToken); return 0;}
在上述示例中,我们使用了LookupPrivilegeValue函数来获取SE_DEBUG_NAME特权的LUID,然后使用AdjustTokenPrivileges函数来启用该特权。请注意,您需要管理员权限来获取和启用特权。