Assigne un processus � un objet Job existant
#include <WinAPIProc.au3>
_WinAPI_AssignProcessToJobObject ( $hJob, $hProcess )
$hJob | Handle de l'objet Job auquel le processus sera associ�. Le handle doit avoir les droits d'acc�s $JOB_OBJECT_ASSIGN_PROCESS. |
$hProcess | Handle du processus � associer � l'objet Job. Le processus ne doit pas d�j� �tre affect� � une t�che. |
Succ�s: | Retourne True. |
�chec: | Retourne False, appelez _WinAPI_GetLastError() pour obtenir des informations suppl�mentaires sur l'erreur. |
Apr�s avoir associ� un processus � un objet Job, le processus est soumis aux limites fix�es pour le travail.
Pour d�finir les limites d'une t�che, utilisez la fonction _WinAPI_SetInformationJobObject().
Un processus peut �tre associ� seulement � une seule t�che.
Le processus h�rite des limites de la t�che auquel il est associ� et ajoute ses informations de compte � la t�che.
Si un processus est associ� � une t�che, tous les processus qu'il cr�e sont associ�s � cette t�che.
_WinAPI_SetInformationJobObject
Consultez AssignProcessToJobObject dans la librairie MSDN.
#include <APIProcConstants.au3> #include <WinAPIConv.au3> #include <WinAPIHObj.au3> #include <WinAPIProc.au3> Local Const $sTemp = @TempDir & '\Test.au3' ; Cr�e un fichier temporaire .au3 Local $hFile = FileOpen($sTemp, 2) For $i = 1 To 3 FileWriteLine($hFile, 'Run(@SystemDir & "\calc.exe")' & @CRLF & 'Sleep(100)') Next FileClose($hFile) ; Ex�cute 3 fois "calc.exe" et attend jusqu'� ce que vous ayez ferm� tous les 3 processus _RunWaitEx(@AutoItExe & '/AutoIt3ExecuteScript "' & $sTemp & '"') ; Supprime le fichier temporaire .au3 FileDelete($sTemp) Func _RunWaitEx($sCmd) ; Id�e originale de 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, DllStructGetPtr($tStartup), DllStructGetPtr($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