How to use job object

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Ray (raywu0601_at_hotmail.com)
Date: 03/08/04


Date: Mon, 8 Mar 2004 20:18:15 +0800

Hi all,

I have a question about how to use job object.
In my project, I have to let user to execute other process,
I can't know which process will be executed in advance.
I want to compare the difference of registry before and after this process
executed.
So I want to know when this process terminate.
I know many processes will be ended after it spawns child processes.
So I tried to use job object to do this.
Here is my codes.

 HANDLE hJob = CreateJobObject(NULL,"myJob");

 STARTUPINFO si;
 PROCESS_INFORMATION pi;
 ZeroMemory( &si, sizeof(si) );
 si.cb = sizeof(si);
 ZeroMemory( &pi, sizeof(pi) );

 if(CreateProcess( NULL, lpCommand, NULL, NULL, FALSE,
                            CREATE_SUSPENDED, NULL, NULL, &si, &pi ))
 {
        AssignProcessToJobObject(hJob, pi.hProcess);
        ResumeThread(pi.hThread);
        WaitForSingleObject(hJob, INFINITE);
        CloseHandle( pi.hProcess );
        CloseHandle( hJob );
 }

But it can't work well.
It looks like the new process will not execute until my process is ended.
Is there any wrong in my codes?

My OS is Win2K.

Thanks!



Relevant Pages

  • Re: How to use job object
    ... I tried my code again and the child process will execute. ... >> I have a question about how to use job object. ... >> Here is my codes. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: How to use job object
    ... > I have a question about how to use job object. ... > Here is my codes. ... > It looks like the new process will not execute until my process is ended. ... > My OS is Win2K. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Why does explorer assign a job object to some processes and not ot
    ... Explorer it is assigned one already hence we cannot assign another Job ... it does not have a Job Object. ... Thats the background to the question, why is it assigning a job object when ... I execute the app from a folder, but when executed from the command line it ...
    (microsoft.public.win32.programmer.kernel)
  • Re: G76 parameter line
    ... esp w/ the older controllers....the controller ... (where your "M" codes are concerned)....often the MTB will decide ... the buffer is executed IIRC. ... the control can execute much of anything. ...
    (alt.machines.cnc)
  • RE: Problem in building a windows service
    ... Public Sub TestService() ... ' try to connect with SQL Server thr SqlHelper; ... then it sits still to wait for next time interval to execute the codes again. ...
    (microsoft.public.dotnet.framework)