锘?!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
delphi 涓叧闂繘紼嬨備唬鐮佸涓?/span>
闇瑕佸紩鐢ㄥ崟鍏? TlHelp32
function KillTask(ExeFileName: string): boolean;
const
PROCESS_TERMINATE = $0001;
var
ContinueLoop: BOOLean;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
res:Integer;
begin
Result :=false;
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); //鑾峰彇榪涚▼鍒楄〃錛岃繑鍥炲揩鐓х殑鍙ユ焺銆?/p>
FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32); //鑾峰緱絎竴涓繘紼嬬殑鍙ユ焺
while Integer(ContinueLoop) <> 0 do
begin
if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =
UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) =
UpperCase(ExeFileName))) then
res := Integer(TerminateProcess(
OpenProcess(PROCESS_TERMINATE,
BOOL(0),
FProcessEntry32.th32ProcessID),
0));
if res<>0 then Result :=True;
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);//褰撳墠榪涚▼鍒楄〃涓墍鏈夌殑蹇収
end;
CloseHandle(FSnapshotHandle);
end;