delphi 中關閉進程。代碼如下 需要引用單元 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); //獲取進程列表,返回快照的句柄。 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;