S
SepSolaraining
Unregistered / Unconfirmed
GUEST, unregistred user!
unit process;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, Tlhelp32, Buttons, StdCtrls, CheckLst;<br><br>type<br> TForm1 = class(TForm)<br> ListBox1: TListBox;<br> Button1: TButton;<br> procedure Button1Click(Sender: TObject);<br> procedure FormCreate(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br> procedure Search(Strings:TStrings);<br><br>implementation<br><br>{$R *.dfm}<br><br> procedure Search(Strings:TStrings); <br> var<br> Snap:THandle; <br> RB:Boolean; <br> PE:TProcessEntry32; <br> begin <br> if Strings=nil then <br> Exit; <br> snap:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); <br> if snap = -1 then Exit;<br> try <br> PE.dwSize:=SizeOf(TProcessEntry32);//这段看不懂 <br> <br> RB:=Process32First(snap,PE);<br> while RB do <br> begin <br> Strings.AddObject(PE.szExeFile,Pointer(PE.th32ProcessID)); //这段看不懂 <br> PE.dwSize:=SizeOf(TProcessEntry32);//这段看不懂 <br> <br> RB:=Process32Next(snap,PE); <br> end; <br> finally <br> CloseHandle(snap); <br> end; <br> end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br> var <br> H:THandle; <br> R:Cardinal;<br>begin<br> H:=OpenProcess(PROCESS_TERMINATE,True,LongInt(ListBox1.Items.Objects<br><br>[ListBox1.ItemIndex])); <br> R:=0; <br> TerminateProcess(H,R);<br> CloseHandle(H);<br> ListBox1.Items.Clear;<br> Search(ListBox1.Items);<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> ListBox1.Items.Clear;<br> Search(ListBox1.Items);<br>end;<br><br>end.<br><br>如果我想指定进程名,比如“cmd.exe”,也就是用TerminateProcess结束cmd.exe,应该怎么写呢?