#include <iostream>
#include <conio.h>
#include <Windows.h>
HANDLE Create(LPCTSTR pszPath)
{
STARTUPINFO si = {0};
PROCESS_INFORMATION pi = {0};
si.cb = sizeof(si);
CreateProcess(pszPath,
NULL,NULL,NULL,FALSE,0,
NULL,NULL,&si,&pi);
return pi.hProcess;
}
void Job()
{
//创建内核对像
HANDLE hJob = CreateJobObject(NULL,TEXT("Job"));
//设置权限
JOBOBJECT_BASIC_UI_RESTRICTIONS ui = {0};
ui.UIRestrictionsClass = JOB_OBJECT_UILIMIT_READCLIPBOARD|JOB_OBJECT_UILIMIT_WRITECLIPBOARD;
SetInformationJobObject(hJob,
JobObjectBasicUIRestrictions,
&ui,sizeof(ui));
//创建进程
HANDLE hProc = Create(TEXT("C:\\Windows\\System32\\mspaint.exe"));
//将进程加入作业
AssignProcessToJobObject(hJob,hProc);
getch();
//结束作业
TerminateJobObject( hJob, 0 );
//关闭Job
CloseHandle(hJob);
}
int main()
{
Job();
return 0;
}
|