都能被结束.(级别高的进程杀不掉)
// WinJob.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "conio.h" #define _WIN32_WINNT 0x0500 #include "windows.h" HANDLE Create( LPSTR 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( ) { //创建Job对象 HANDLE hJob = CreateJobObject( NULL, "MyJob" ); //设置权限 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( "c:\\windows\\system32\\mspaint.exe" ); //将进程加入作业 AssignProcessToJobObject( hJob, hProc ); hProc = Create( "c:\\windows\\system32\\mspaint.exe" ); AssignProcessToJobObject( hJob, hProc ); getch( ); //结束作业 TerminateJobObject( hJob, 0 ); //关闭Job CloseHandle( hJob ); } int main(int argc, char* argv[]) { Job( ); return 0; }