windows核心编程 第五章

#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);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值