Author: Misha Moellner Kill a task using only the .exe name Answer: This little function closes all applications with the same .exe-name. Example: 1 2 KillTask('notepad.exe'); 3 KillTask('iexplore.exe'); Working on Win9x/2k, but apparently not on WinNT systems (never tried on my own) 4 uses 5 Tlhelp32, Windows, SysUtils; 6 7 function KillTask(ExeFileName: string): integer; 8 const 9 PROCESS_TERMINATE = $0001; 10 var 11 ContinueLoop: BOOL; 12 FSnapshotHandle: THandle; 13 FProcessEntry32: TProcessEntry32; 14 begin 15 result := 0; 16 17 FSnapshotHandle := CreateToolhelp32Snapshot 18 (TH32CS_SNAPPROCESS, 0); 19 FProcessEntry32.dwSize := Sizeof(FProcessEntry32); 20 ContinueLoop := Process32First(FSnapshotHandle, 21 FProcessEntry32); 22 23 while integer(ContinueLoop) <> 0 do 24 begin 25 if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) = 26 UpperCase(ExeFileName)) 27 or (UpperCase(FProcessEntry32.szExeFile) = 28 UpperCase(ExeFileName))) then 29 Result := Integer(TerminateProcess(OpenProcess( 30 PROCESS_TERMINATE, BOOL(0), 31 FProcessEntry32.th32ProcessID), 0)); 32 ContinueLoop := Process32Next(FSnapshotHandle, 33 FProcessEntry32); 34 end; 35 36 CloseHandle(FSnapshotHandle); 37 end;