Function Reference


_WinAPI_QueryInformationJobObject

Retrieves limit and job state information from the job object

#include <WinAPIProc.au3>
_WinAPI_QueryInformationJobObject ( $hJob, $iJobObjectInfoClass, ByRef $tJobObjectInfo )

Parameters

$hJob Handle to the job whose information is being queried. The handle must have the
$JOB_OBJECT_QUERY access right. If this value is 0 and the calling process is associated
with a job, the job associated with the calling process is used.
$iJobObjectInfoClass The information class for the limits to be queried. This parameter specifies the type
of $tJobObjectInfo structure, valid values:
1 - $tagJOBOBJECT_BASIC_ACCOUNTING_INFORMATION
2 - $tagJOBOBJECT_BASIC_LIMIT_INFORMATION
3 - $tagJOBOBJECT_BASIC_PROCESS_ID_LIST
4 - $tagJOBOBJECT_BASIC_UI_RESTRICTIONS
5 - $tagJOBOBJECT_SECURITY_LIMIT_INFORMATION
8 - $tagJOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION
9 - $tagJOBOBJECT_EXTENDED_LIMIT_INFORMATION
11 - $tagJOBOBJECT_GROUP_INFORMATION
$tJobObjectInfo $tagJOBOBJECT_* structure (see above) that retrieves the limit and job state information.
This structure must be created before function call.

Return Value

Success: The length of data (in bytes) written to the structure pointed to by the
$tJobObjectInfo parameter.
Failure: 0, call _WinAPI_GetLastError() to get extended error information.

See Also

Search QueryInformationJobObject in MSDN Library.

Example

#include <WinAPIConv.au3>
#include <WinAPIHObj.au3>
#include <WinAPIProc.au3>

Local Const $sTemp = @TempDir & '\Test.au3'

; Create temporary .au3 file
Local $hFile = FileOpen($sTemp, 2)
For $i = 1 To 3
        FileWriteLine($hFile, 'Run(@SystemDir & "\notepad.exe")' & @CRLF & 'Sleep(100)')
Next
FileClose($hFile)

; Run 3 times the "notepad.exe" and wait until you have closed all 3 processes
_RunWaitEx(@AutoItExe & ' /AutoIt3ExecuteScript "' & $sTemp & '"')

; Delete temporary .au3 file
FileDelete($sTemp)

Func _RunWaitEx($sCmd)
        ; Original idea by amel27

        Local $tProcess = DllStructCreate($tagPROCESS_INFORMATION)
        Local $tStartup = DllStructCreate($tagSTARTUPINFO)
        Local $tInfo = DllStructCreate($tagJOBOBJECT_BASIC_ACCOUNTING_INFORMATION)

        Local $hJob = _WinAPI_CreateJobObject()
        If Not $hJob Then Return SetError(1, 0, 0)

        DllStructSetData($tStartup, 'Size', DllStructGetSize($tStartup))
        If Not _WinAPI_CreateProcess('', $sCmd, 0, 0, 0, BitOR($CREATE_BREAKAWAY_FROM_JOB, $CREATE_SUSPENDED), 0, 0, $tStartup, $tProcess) Then
                Return SetError(1, _WinAPI_CloseHandle($hJob), 0)
        EndIf
        Local $hProcess = DllStructGetData($tProcess, 'hProcess')
        Local $hThread = DllStructGetData($tProcess, 'hThread')
        _WinAPI_AssignProcessToJobObject($hJob, $hProcess)
        _WinAPI_ResumeThread($hThread)
        _WinAPI_CloseHandle($hThread)
        Do
                If Not _WinAPI_QueryInformationJobObject($hJob, 1, $tInfo) Then
                        ExitLoop
                EndIf
                Sleep(100)
        Until Not DllStructGetData($tInfo, 'ActiveProcesses')
        _WinAPI_CloseHandle($hProcess)
        _WinAPI_CloseHandle($hJob)
        Return 1
EndFunc   ;==>_RunWaitEx

Func _WinAPI_ResumeThread($hThread)
        Local $aRet = DllCall('kernel32.dll', 'dword', 'ResumeThread', 'ptr', $hThread)
        If @error Or (_WinAPI_DWordToInt($aRet[0]) = -1) Then Return SetError(1, 0, -1)

        Return $aRet[0]
EndFunc   ;==>_WinAPI_ResumeThread