procedure KillCommandProcess;<br>var<br> ProcessSnapShotHandle: THandle;<br> ProcessEntry: TProcessEntry32;<br> ProcessHandle: THandle;<br> Ret: BOOL;<br>begin<br> ProcessSnapShotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);<br> if ProcessSnapShotHandle>0 then<br> begin<br> ProcessEntry.dwSize:=SizeOf(TProcessEntry32);<br> Ret:=Process32First(ProcessSnapShotHandle, ProcessEntry);<br> while Ret do<br> begin<br> if ProcessEntry.szExeFile='EXCEL.EXE' then //你要关闭的程序 注意:大小写敏感<br> begin<br> ProcessHandle:=OpenProcess(PROCESS_TERMINATE, False,<br> ProcessEntry.th32ProcessID);<br> if ProcessHandle>0 then<br> begin<br> TerminateProcess(ProcessHandle, 0);<br> CloseHandle(ProcessHandle)<br> end<br> end;<br> Ret:=Process32Next(ProcessSnapShotHandle, ProcessEntry)<br> end;<br> CloseHandle(ProcessSnapShotHandle)<br> end<br>end;