Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 21st, 2012  |  syntax: C++  |  size: 0.75 KB  |  views: 157  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. HANDLE job = CreateJobObject(NULL, NULL);
  2. if (!job) ...
  3. JOBOBJECT_BASIC_LIMIT_INFORMATION jobLimit = { };
  4. jobLimit.LimitFlags = JOB_OBJECT_LIMIT_ACTIVE_PROCESS;
  5. jobLimit.ActiveProcessLimit = 1;
  6. if(! SetInformationJobObject(job, JobObjectBasicLimitInformation, &jobLimit, sizeof(jobLimit)) ) ...
  7. STARTUPINFO si = { sizeof(si) };
  8. PROCESS_INFORMATION pi;
  9. if(! CreateProcess(0, yourcommand, 0, 0, FALSE, CREATE_SUSPENDED | CREATE_BREAKAWAY_FROM_JOB , 0, 0, &si, &pi) ) ...
  10. if(! AssignProcessToJobObject(job, pi.hProcess) ) ...
  11. ResumeThread(pi.hThread);
  12. WaitForSingleObject(pi.hProcess, INFINITE); //Normally you would wait on the job, but since there can only be one process this is ok
  13.  
  14. CloseHandle(pi.hProcess);
  15. CloseHandle(pi.hThread);
  16. CloseHandle(job);