0

Could someone please help me? I'm trying to create a jobobject with JOB_OBJECT_SECURITY_ONLY_TOKEN but SetInformationJobObject always fails with error code 6 ( Invalid handle ). Here is my code:

HANDLE Job( CreateJobObject( NULL, NULL ) );
if( !Job )
{
    wprintf( L"Could not create job object, error %d\n", GetLastError() );
    return 1;
}

JOBOBJECT_SECURITY_LIMIT_INFORMATION SecLimit = { 0 };
SecLimit.SecurityLimitFlags = JOB_OBJECT_SECURITY_ONLY_TOKEN;

if ( !SetInformationJobObject( Job, JobObjectSecurityLimitInformation, &SecLimit, sizeof( SecLimit ) ) )
{
    wprintf( L"Could not associate job with IO completion port, error %d\n", GetLastError() );
    return 1;
}

I am trying to run this app on XP! Thanks!

kampi
  • 2,362
  • 12
  • 52
  • 91
  • Check the MSDN article: `This flag is not supported` – Hans Passant Nov 19 '12 at 14:41
  • I found that too. But acording to this article http://blog.yezhucn.com/dllproc/assignprocesstojobobject.htm a jobobject requires the JOB_OBJECT_SECURITY_ONLY_TOKEN security limitation, so do i grant it? – kampi Nov 19 '12 at 15:01
  • @HansPassant: it's still supported for XP, so this isn't the OPs problem. – Harry Johnston Nov 19 '12 at 20:12

1 Answers1

0

You haven't set SecLimit.JobToken to a valid handle to a restricted token. That's why you're getting an invalid handle error. If you use the JOB_OBJECT_SECURITY_ONLY_TOKEN flag, SecLimit.JobToken is mandatory.

Unless there is some particular reason why you need to force processes in the job to use a restricted token, don't use the JOB_OBJECT_SECURITY_ONLY_TOKEN flag.

Note that the article you reference does not in fact say that this flag is required. It only says that if you use this flag the process must be created suspended in order to assign it to the job object.

Harry Johnston
  • 35,639
  • 6
  • 68
  • 158
  • The reason why i want to use the JOB_OBJECT_SECURITY_ONLY_TOKEN flag is, that AssignProcessToJobObject fails with Access Denied on Windows XP SP3 machines( on Windows 7 it works fine). Unfortunately i didn't find any reference or working code to see what am i doing wrong, so i thought maybe this solution could work. Please see my other question, maybe you can help. http://stackoverflow.com/questions/13449531/why-does-assignprocesstojobobject-fail-on-xp-with-error-access-denied Thans in advance! – kampi Nov 19 '12 at 21:56