Search code examples
jobscreateprocess

IsProcessInJob with GetCurrentProcess aways true


(Visual Studio 2010 - C++) Hello,

I'm trying to set a JOB to a process, but AssignProcessToJobObject returns ACCESS_DENIED and IsProcessInJob returns TRUE.

I call IsProcessInJob to a process immediately after call CreateProcess (Suspended) end tried call IsProcessInJob with my process (a few lines after main entry point) and it returns true.

void main()
{   
    BOOL bIsInJob;

    IsProcessInJob( GetCurrentProcess(), NULL, &bIsInJob );
    printf( "IsProcessInJob (me): %s\n", bIsInJob ? "true" : "false" ); 
// RET True ! inside and outside IDE
   ...

Someone saw it before?

Thanks for any help. Sources: Kill child process when parent process is killed How do I automatically destroy child processes in Windows?


Solution

  • I found.

    For some reason, my process was child of Explorer.exe then Explorer set a job to my process and the notepad (my child) inherits this job.

    I could not find until see with ProcessExplorer. I can not saw my process in process list, when i find below Winlogon->Explorer, i understood.

    Resolution: CREATE_BREAKAWAY_FROM_JOB

    if (!CreateProcess(L"c:\\windows\\system32\\notepad.exe",  L"", NULL, NULL, FALSE,
            CREATE_BREAKAWAY_FROM_JOB, NULL, NULL, &startupInfo, &processInformation))
    ...
    

    Thanks for your comments, patience and time.