none
AssignProcessToJobObject always return "access denied" on Vista.

    Question

  • Hello,

    My software is  to launch other programs and wait until they finish. I use job to handle processes spawned to ensure all processes finished correctly. The code was written one year ago and it works fine on Windows 2000 and XP with all SP packs.

    The code is something like following:

        HANDLE hjob = CreateJobObject(NULL, JOB_ID);

    //Debug with opening this job with Open JobObject(JOB_OBJECT_ALL_ACCESS,False,JOB_ID) and return correct handle, means the job has required priviledge

        STARTUPINFO si = { sizeof(si) };
        PROCESS_INFORMATION pi;

        CreateProcess(NULL, "notepad.exe", NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &si, &pi);

    //Open process with OpenProcess(PROCESS_ALL_ACCESS,False, pi.dwProcessId), yes, it also works

        AssignProcessToJobObject(hjob, pi.hProcess);

    //Always get ACCESS_DENIED when called under Windows Vista RTM while works perfectly under Win2K or XP.

        ResumeThread(pi.hThread);
        CloseHandle(pi.hThread);

        HANDLE h[2];
        h[0] = pi.hProcess;
        h[1] = hjob;
        DWORD dw = WaitForMultipleObjects(2, h, FALSE, INFINITE);
        switch (dw -WAIT_OBJECT_0) {
            case 0:
                // The process has terminated?
                break;
            case 1:
                // All of the job allotted CPU time was used?
                break;
        }

        // Clean-up properly
        CloseHandle(pi.hProcess);
        CloseHandle(hjob);
    }

    I stuck with this problem for several days, I guess it's most probably caused bt UAC, can anyone help please?

     

    Thursday, January 25, 2007 4:08 AM

All replies

  • Thomas -

    Thank you for your post. I'm a development lead here at Microsoft and can help you with your question.

    On Vista, the Program Compatibility Assistant was added to help diagnose application compatibility problems. To allow us to accurately monitor applications, we leverage job objects for a certain class of applications. Specifically, this class of applications include anything launched from the Windows shell. Applications launched from a command-prompt are excluded.

    If the application is marked with a UAC manifest, the application will be excluded permanently from the Program Compatibility Assistant.

    To correct your problem, please mark your application with a UAC manifest. More information on how to do this can be found here:

    http://msdn2.microsoft.com/en-us/library/aa480150.aspx

    You can read more about the Progarm Compatbility Assistant here:

    http://msdn2.microsoft.com/en-us/library/aa480152.aspx#appcomp_topic18

    Please let me know if I can be of any additional help.

    Raymond Parsons
    Microsoft Corporation

    Monday, January 29, 2007 5:49 PM
  • Hello Raymond,

    Thanks for your reply, it is very helpful and I know how PCA works.

    I always have a UAC manifest file like following before this post. Normally I launch programs with Total Commander 6(without the manifest), all attampts failed. But when I try to launch my program from desktop shortcut, success. Sorry I seldom launch programs from desktop.

    Does it mean if my program is launched by a program not excluded from PCA, the problem will persist? (At least from my tests, it looks like that). 

    Part of my manifest:

      <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
        <security>
          <requestedPrivileges>
            <requestedExecutionLevel
              level="requireAdministrator"
              uiAccess="false"/>
            </requestedPrivileges>
        </security>
      </trustInfo>

    Thank you.

    Tuesday, January 30, 2007 7:14 AM