带有GetCurrentProcess的IsProcessInJob是真的

时间:2011-08-27 05:51:16

标签: jobs createprocess

(Visual Studio 2010 - C ++) 您好,

我正在尝试将JOB设置为进程,但AssignProcessToJobObject返回ACCESS_DENIED并且IsProcessInJob返回TRUE。

我在调用CreateProcess(Suspended)结束后尝试使用我的进程调用IsProcessInJob(在主入口点之后的几行)后立即调用IsProcessInJob进程,并返回true。

void main()
{   
    BOOL bIsInJob;

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

之前有人见过吗?

感谢您的帮助。 资料来源: Kill child process when parent process is killed How do I automatically destroy child processes in Windows?

1 个答案:

答案 0 :(得分:1)

我找到了。

出于某种原因,我的进程是Explorer.exe的子进程,然后Explorer将作业设置为我的进程,记事本(我的孩子)继承了这个作业。

在看到ProcessExplorer之前我找不到。我无法在进程列表中看到我的进程,当我在Winlogon-> Explorer下面找到时,我明白了。

决议:CREATE_BREAKAWAY_FROM_JOB

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

感谢您的评论,耐心和时间。