#include <iostream>
#include <Windows.h>
using namespace std;
void StartRestrictedProcess()
{
HANDLE hjob = CreateJobObject(NULL,NULL);
JOBOBJECT_BASIC_LIMIT_INFORMATION jobli = {0};
jobli.PriorityClass = IDLE_PRIORITY_CLASS;
jobli.PerJobUserTimeLimit .QuadPart = 10000000;
jobli.LimitFlags = JOB_OBJECT_LIMIT_PRIORITY_CLASS | JOB_OBJECT_LIMIT_JOB_TIME;
SetInformationJobObject(hjob,JobObjectBasicLimitInformation,&jobli,sizeof(jobli));
JOBOBJECT_BASIC_UI_RESTRICTIONS jobuir;
jobuir.UIRestrictionsClass = JOB_OBJECT_UILIMIT_NONE;
jobuir.UIRestrictionsClass |= JOB_OBJECT_UILIMIT_EXITWINDOWS;
jobuir.UIRestrictionsClass |= JOB_OBJECT_UILIMIT_HANDLES;
SetInformationJobObject(hjob,JobObjectBasicUIRestrictions,&jobuir,sizeof(jobuir));
STARTUPINFO si = {sizeof(si)};
PROCESS_INFORMATION pi;
CreateProcess(NULL,"CMD",NULL,NULL,FALSE,CREATE_SUSPENDED,NULL,NULL,&si,&pi);
AssignProcessToJobObject(hjob,pi.hProcess);
ResumeThread(pi.hThread);
CloseHandle(pi.hThread);
HANDLE h[2];
h[0] = pi.hProcess;
h[1] = hjob;
DWORD dw = WaitForMultipleObjects(2,h,FALSE,INFINITE);
switch(dw-WAIT_OBJECT_0)
{
case 0:
break;
case 1:
break;
}
CloseHandle(pi.hProcess);
CloseHandle(hjob);
}
windows核心编程 第五章
最新推荐文章于 2022-09-13 00:10:06 发布