1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
procedure killAllProcessesFrom(procId : DWORD);
var
SnapShot: Cardinal;
ProcessEntry: TProcessEntry32;
processhandle : thandle;
begin
//Création de "l'instantané"
SnapShot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
//En cas d'erreur on sort
If SnapShot = 0 then Exit;
ProcessEntry.dwSize := SizeOf(ProcessEntry);
//On liste les processus
If Process32First(SnapShot, ProcessEntry) then
begin
Repeat
//si le processus courant est le parent, on descend dans l'arbre
if ProcessEntry.th32ParentProcessID = procId
then killAllProcessesFrom(ProcessEntry.th32ProcessID)
until not Process32Next(SnapShot, ProcessEntry)
end;
//Libération de l'instantané
CloseHandle(SnapShot);
//Suppression du process courant
processhandle := openprocess(PROCESS_TERMINATE, FALSE, procID);
terminateprocess(processhandle, 4);
End; |
Partager