Posted on 2007-08-22 00:04
紫雨轩 C++ 阅读(1349)
评论(0) 编辑 收藏 引用 所属分类:
Win32 SDK
void AdjustPrivilege(int pid, BOOL bEnable)
{
HANDLE hProcess;
HANDLE hToken=0;
TOKEN_PRIVILEGES tkp;
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = 0;
if (bEnable)
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if (LookupPrivilegeValue(NULL, "SeDebugPrivilege", &tkp.Privileges[0].Luid))
{
if (hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid))
{
if (OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &hToken))
{
if (AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, NULL))
{
CloseHandle(hToken);
}
}
CloseHandle(hProcess);
}
}
}