来自:jsxjd, 时间:2002-11-22 12:19:00, ID:1450931<br>----------------------------------------------------------------<br><br>//获得进程列表,并终止 Excel 进程<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> FSnapshotHandle:THandle;<br> FProcessEntry32:TProcessEntry32;<br> Ret : BOOL;<br> ProcessID : integer;<br> s:string;<br>begin<br> FSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);<br> FProcessEntry32.dwSize:=Sizeof(FProcessEntry32);<br> Ret:=Process32First(FSnapshotHandle,FProcessEntry32);<br> Memo1.clear;<br> while Ret do<br> begin<br> Memo1.lines.add(FProcessEntry32.szExeFile);<br> s:=ExtractFileName(FProcessEntry32.szExeFile);<br> if s='EXCEL.EXE' then<br> begin<br> ProcessID:=FProcessEntry32.th32ProcessID;<br> TerminateProcess(OpenProcess(PROCESS_TERMINATE,false,ProcessID),1);<br> s:='';<br> end;<br> Ret:=Process32Next(FSnapshotHandle,FProcessEntry32);<br> end;<br>end;<br>