Jump to content

Calls to _WinAPI_SetInformationJobObject are unsuccessful

Recommended Posts

Hi. I wanted to impose some memory usage limits on a process and found this: https://docs.microsoft.com/en-us/windows/win32/procthread/job-objects
Job Objects look like the perfect tool for the job at hand, but no matter what I try, the _WinAPI_SetInformationJobObject function never succeeds.
The problem can be reproduced as follows:

#include <WinAPIProc.au3>
#include <WinAPIDiag.au3>
#include <ProcessConstants.au3>

Local $hJob = _WinAPI_CreateJobObject()
Local $tJobObjectInfo = DllStructCreate($tagJOBOBJECT_EXTENDED_LIMIT_INFORMATION)
DllStructSetData($tJobObjectInfo, "LimitFlags", 0x2000) ;~ JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE
_WinAPI_SetInformationJobObject($hJob, $tagJOBOBJECT_EXTENDED_LIMIT_INFORMATION, $tJobObjectInfo)
If Not _WinAPI_SetInformationJobObject($hJob, $tagJOBOBJECT_EXTENDED_LIMIT_INFORMATION, $tJobObjectInfo) Then
    MsgBox(0, 'SetInformationJobObject() failed', _WinAPI_GetLastError())
    MsgBox(0, 'Success!', '')

I based the code off the accepted answer in https://stackoverflow.com/a/9164742 but for some reason it always fails with an error code of 87 (0x57).

Any clues?

Share this post

Link to post
Share on other sites

Found the cause. The docs for the $iJobObjectInfoClass parameter say this:

The information class for the limits to be set. This parameter specifies the type
of $tJobObjectInfo structure, valid values:

It caused me to pass $tagJOBOBJECT_EXTENDED_LIMIT_INFORMATION in there (which is a string describing the struct), but instead I had to specify the number 9 literally.
Now it works as expected.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...