The function force terminate process by its name.
1 2 3 4 5 6 7 8 9 10 |
Uses Tlhelp32; ... var procName: string; begin procName:= 'taskmgr.exe'; killTask(procName); end; |
Options
pName - process name
Result
True if the operation is successful, False if not.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
function killTask(procName:string): boolean; const PROCESS_TERMINATE=$0001; var Co:BOOL; FS:THandle; FP:TProcessEntry32; begin result:= false; FS:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); FP.dwSize:=Sizeof(FP); Co:=Process32First(FS,FP); while integer(Co) <> 0 do begin if ((UpperCase(ExtractFileName(FP.szExeFile))=UpperCase(procName)) or (UpperCase(FP.szExeFile)=UpperCase(procName))) then Result:= TerminateProcess(OpenProcess(PROCESS_TERMINATE, BOOL(0), FP.th32ProcessID),0); Co:=Process32Next(FS,FP); end; CloseHandle(FS); end; |