function KillTask(ExeFileName: string): integer; //杀死进程的函数,来对付防火墙进程。<br>const<br> PROCESS_TERMINATE=$0001; //进程的PROCESS_TERMINATE访问权限<br>var<br> ContinueLoop: BOOL;<br> FSnapshotHandle: THandle;<br> FProcessEntry32: TProcessEntry32;<br>begin<br> result:= 0;<br> FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);<br> //获取系统所有进程快照<br> FProcessEntry32.dwSize := Sizeof(FProcessEntry32);<br> //调用Process32First前用Sizeof(FProcessEntry32)填充FProcessEntry32.dwSize<br> ContinueLoop := Process32First(FSnapshotHandle,FProcessEntry32);<br> //获取快照中第一个进程信息并保存到FProcessEntry32结构体中<br> while integer(ContinueLoop) <> 0 do<br> //循环枚举快照中所有进程信息<br> begin<br> if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile))=UpperCase(ExeFileName))<br> or (UpperCase(FProcessEntry32.szExeFile)=UpperCase(ExeFileName))) then<br> //找到要中止的进程名<br> Result := Integer(TerminateProcess(OpenProcess(PROCESS_TERMINATE, BOOL(0),<br> FProcessEntry32.th32ProcessID), 0));<br> //中止进程<br> ContinueLoop := Process32Next(FSnapshotHandle,FProcessEntry32);<br> //查找下一个符合条件进程<br> end;<br>end;