#include <WinAPI.au3>
_RunWait("test1.exe")
ConsoleWrite("==> "& @error &@CRLF)
Func _RunWait($sCMD)
Local Const $tagJobObjectInfoClass1 = "int64 TotalUserTime;int64 TotalKernelTime;int64 ThisPeriodTotalUserTime;" & _
"int64 ThisPeriodTotalKernelTime;dword TotalPageFaultCount;dword TotalProcesses;dword ActiveProcesses;dword TotalTerminatedProcesses"
Local $aRet = DllCall("kernel32.dll", "hwnd", "CreateJobObject", "ptr", 0, "ptr", 0)
If IsArray($aRet)=0 Or $aRet[0]=0 Then Return SetError(1, 0, False)
Local $hJob = $aRet[0], $hProcess, $hThread
Local $tJI = DllStructCreate($tagJobObjectInfoClass1), $pJI = DllStructGetPtr($tJI)
Local $tPI = DllStructCreate($tagPROCESS_INFORMATION), $pPI = DllStructGetPtr($tPI)
Local $tSI = DllStructCreate($tagSTARTUPINFO), $pSI = DllStructGetPtr($tSI)
DllStructSetData($tSI, 'Size', DllStructGetSize($tSI))
If Not _WinAPI_CreateProcess("", $sCMD, 0, 0, False, 4, 0, 0, $pSI, $pPI) Then Return SetError(2, _WinAPI_CloseHandle($hJob), False)
$hProcess = DllStructGetData($tPI, 'hProcess')
$hThread = DllStructGetData($tPI, 'hThread')
DllCall("kernel32.dll", "BOOL", "AssignProcessToJobObject", "hwnd", $hJob, "hwnd", $hProcess)
DllCall("kernel32.dll", "dword", "ResumeThread", "hwnd", $hThread)
_WinAPI_CloseHandle($hThread)
Do
DllCall("kernel32.dll", "BOOL", "QueryInformationJobObject", "hwnd", $hJob, _
"int", 1, "ptr", $pJI, "dword", DllStructGetSize($tJI), "ptr", 0)
Sleep(1000)
Until DllStructGetData($tJI, "ActiveProcesses") =0
_WinAPI_CloseHandle($hProcess)
_WinAPI_CloseHandle($hJob)
Return True
EndFunc