function KillTask(ExeFileName: string): Integer;<br>const<br> PROCESS_TERMINATE = $0001;<br>var<br> ContinueLoop: BOOL;<br> FSnapshotHandle: THandle;<br> FProcessEntry32: TProcessEntry32;<br>begin<br> Result := 0;<br> FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);<br> FProcessEntry32.dwSize := SizeOf(FProcessEntry32);<br> ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);<br> //'正准备关闭主程序...';<br> while Integer(ContinueLoop) <> 0 do<br> begin<br> if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =<br> UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) =<br> UpperCase(ExeFileName))) then<br> Result := Integer(TerminateProcess(<br> OpenProcess(PROCESS_TERMINATE,<br> BOOL(0),<br> FProcessEntry32.th32ProcessID),<br> 0));<br> ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);<br> //'正在关闭主程序,请等待...';<br> end;<br> CloseHandle(FSnapshotHandle);<br>end;<br>{<br>调用方法<br> KillTask('NotePad.exe');<br>这里'NotePad.exe是在进程管理器中的映像名称<br> }<br>