不用hook 实现挂机锁

不用hook 实现挂机锁
创建作业对象,关联winlogon.exe 进程 Winlogon控制重启,关机,注销等动作。设置作业对象的属性为JOB_OBJECT_UILIMIT_EXITWINDOWS (参考
http://msdn.microsoft.com/en-us/library/ms684152(VS.85).aspx )

即可 Prevents processes associated with the job from calling the ExitWindows or ExitWindowsEx function.

// 挂机
BOOL res = FALSE;
JOBOBJECT_BASIC_UI_RESTRICTIONS JobInfo;
ZeroMemory(&JobInfo, sizeof(JOBOBJECT_BASIC_UI_RESTRICTIONS));
JobInfo.UIRestrictionsClass = JOB_OBJECT_UILIMIT_EXITWINDOWS;

EnableDebugPriv(SE_DEBUG_NAME);
// 建立JOB 对象 命名为WINLOCK
HANDLE hjob = CreateJobObject(NULL, TEXT("WINLOCK"));

SetInformationJobObject(hjob, JobObjectBasicUIRestrictions, &JobInfo, sizeof(JobInfo));


DWORD Pid = GetProcessId("winlogon.exe");
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, Pid);

if (hProcess == NULL)
{
   MessageBox("打开winlogon进程失败");
   return;
}

res = AssignProcessToJobObject(hjob,hProcess);//将进程和对象关联起来
if (!res)
{
   MessageBox("挂机失败");
}

你可能感兴趣的:(不用hook 实现挂机锁)