Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3500320
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:43:09+00:00 2026-05-18T12:43:09+00:00

I can’t seem to use the AssignProcessToJobObject function to assign the current process to

  • 0

I can’t seem to use the AssignProcessToJobObject function to assign the current process to a job object handle given by CreateJobObject. This has been asked a few times already on StackOverflow, but so far none of the solutions (which usually boil down to embedding an UAC manifest) seem to work for me.

I’m using MSVC9 on Windows 7 for this. Here’s the source code for my sample application and a small manifest I’m embedding (which supposedly fixes the problem – but not for me):

My sample application (main.cpp):

#include <windows.h>

static void dumpLastError()
{
    LPVOID lpMsgBuf;
    DWORD dw = GetLastError();

    FormatMessage(
        FORMAT_MESSAGE_ALLOCATE_BUFFER |
        FORMAT_MESSAGE_FROM_SYSTEM,
        NULL,
        dw,
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
        (LPTSTR) &lpMsgBuf,
        0, NULL );
    OutputDebugStringA( (LPTSTR)lpMsgBuf );

    LocalFree(lpMsgBuf);
}

int main()
{
    HANDLE job = CreateJobObjectA( NULL, "demo job 123" );
    if ( !job ) {
        OutputDebugStringA( "CreateJobObject failed" );
        dumpLastError();
        return 1;
    }

    if ( !AssignProcessToJobObject( job, GetCurrentProcess() ) ) {
        OutputDebugStringA( "AssignProcessToJobObject failed" );
        dumpLastError();
        return 1;
    }

    return 0;
}

The UAC manifest (main.exe.manifest):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
   <ms_asmv3:trustInfo xmlns:ms_asmv3="urn:schemas-microsoft-com:asm.v3">
      <ms_asmv3:security>
         <ms_asmv3:requestedPrivileges>
            <ms_asmv3:requestedExecutionLevel level="requireAdministrator"/>
         </ms_asmv3:requestedPrivileges>
      </ms_asmv3:security>
   </ms_asmv3:trustInfo>
</assembly>

I build this sample by running

cl main.cpp
mt -manifest main.exe.manifest -outputresource:main.exe;1

Unfortunately, running my main.exe sample after these steps still yields an ‘Access denied’ error in debug output when attempting the AssignProcessToJobObject call. Does anybody know why that is?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T12:43:10+00:00Added an answer on May 18, 2026 at 12:43 pm

    I followed a number of discussions at one point relating to job objects and UAC manifests. The only piece of information that helped me around the same problem that you’re having was that this security feature (introduced in Vista) is apparently not enforced when run from a cmd.

    I assume you’re launching PyCmd from the start menu. Try launching it from cmd, and I’ll bet the problem will go away there too.

    What I ended up doing (to run mintty with cygwin) was to make a mintty.bat which said

    start mintty.exe
    

    and then a shortcut to mintty.bat which had a property set to run ‘minimized’ (I forget the exact wording). This allows the shell I wanted to be launched from the start menu and still work as if it had been launched from cmd.exe.

    As a side-note, I’d love it if someone would come along and actually explain the problem at a build-level, and how to fix it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I get a 'when to use' for these and others? <% %> <%#
Does anyone know how can I replace this 2 symbol below from the string
Can somebody point me to a resource that explains how to go about having
Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of
Can you cast a List<int> to List<string> somehow? I know I could loop through
can you recommend some good ASP.NET tutorials or a good book? Should I jump
Can a LINQ enabled app run on a machine that only has the .NET
Can anyone tell me how I can display a status message like 12 seconds
Can you tell me what is the difference between abstraction and information hiding in
Can anyone recommend a good library for generating an audio file, such as mp3,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.