下面是去年计算机世界上的一段代码,功能是查找出所有的进程,如果点击按钮则会终止进<br>程,但是肯定可以满足你的要求:<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,TLHelp32,<br> StdCtrls;<br><br>type<br><br>TProcessInfo=Record<br> ExeFile:String;<br> ProcessId
WORD;<br>End;<br> ProcessInfo=^TProcessInfo;<br><br> TForm1 = class(TForm)<br> ListBox1: TListBox;<br> Button1: TButton;<br> procedure FormCreate(Sender: TObject);<br> procedure ProcessList(var PList:TList);<br> procedure Button1Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> Current:TList;<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.ProcessList(var pList:TList);<br> var p
rocessInfo;<br> ok:Bool;<br> ProcessListHandle:THandle;<br> ProcessStruct:TProcessEntry32;<br>Begin<br> PList:=TList.Create;<br> PList.Clear;<br> ProcessListHandle:=CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS,0);<br> ProcessStruct.dwSize:=Sizeof(ProcessStruct);<br> ok:=Process32First(ProcessListHandle,ProcessStruct);<br> while Integer(ok)<>0 do Begin<br> new(p);<br> p.ExeFile:=ProcessStruct.szExeFile;<br> p.ProcessID:=ProcessStruct.th32ProcessID;<br> PList.Add(p);<br> ok:=Process32Next(ProcessListHandle,ProcessStruct);<br> End;<br>End;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br> var i:Integer;<br> p
RocessInfo;<br>begin<br> current:=TList.Create;<br> Current.Clear;<br> ListBox1.Clear;<br> ProcessList(Current);<br> for i:=0 to Current.Count-1 do Begin<br> new(p);<br> p:=Current.Items
;<br> ListBox1.Items.Add(p.ExeFile);<br> End;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br> var h:THandle;<br> aWORD;<br> pRocessInfo;<br>begin<br> if ListBox1.ItemIndex>=0 then Begin<br> p:=Current.Items[ListBox1.ItemIndex];<br> h:=openProcess(Process_All_Access,true,p.ProcessID);<br> GetExitCodeProcess(h,a);<br> if Integer(TerminateProcess(h,a))<>0 then Begin<br> ListBox1.Clear;<br> FormCreate(Self);<br> End;<br> End; <br>end;<br><br>end.<br>