请问高手怎样用listbox和api函数(openprocess,terminateprocess)杀进程?(有源代码更好哈)谢谢了啊~~~(50分)

N

netmax

Unregistered / Unconfirmed
GUEST, unregistred user!
请问高手怎样用listbox和api函数(openprocess,terminateprocess)杀进程?(有源代码更好哈)谢谢了啊~~~<br>
 
implementation<br>&nbsp; &nbsp; &nbsp; uses TLHelp32;<br>{$R *.dfm}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; &nbsp; &nbsp; &nbsp; pe:TProcessEntry32;<br>&nbsp; &nbsp; &nbsp; &nbsp; ph,h:THandle;<br>begin<br>&nbsp; &nbsp; &nbsp; &nbsp; h:=0;<br>&nbsp; &nbsp; &nbsp; &nbsp; listbox1.Items.Clear;<br>&nbsp; &nbsp; &nbsp; &nbsp; ph:=CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS,0);<br>&nbsp; &nbsp; &nbsp; &nbsp; if ph&lt;&gt;0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; pe.dwSize:=sizeof(pe);<br>&nbsp; &nbsp; &nbsp; &nbsp; if process32First(ph,pe) then<br>&nbsp; &nbsp; &nbsp; &nbsp; repeat<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;listbox1.Items.Add(pe.szExeFile);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;until not Process32Next(ph,pe);<br>&nbsp; &nbsp; &nbsp; &nbsp; closehandle(ph);<br>end;<br><br>procedure TForm1.ListBox1DblClick(Sender: TObject);<br>var<br>&nbsp; &nbsp; &nbsp; &nbsp; ph:Thandle;<br>&nbsp; &nbsp; &nbsp; &nbsp; idid:dword;<br>&nbsp; &nbsp; &nbsp; &nbsp; tmp:string;<br>&nbsp; &nbsp; &nbsp; &nbsp; p:integer;<br>&nbsp; &nbsp; &nbsp; &nbsp; ret:boolean;<br>&nbsp; &nbsp; &nbsp; &nbsp; a: DWORD;<br>begin<br>&nbsp; &nbsp; &nbsp; tmp:=listbox1.Items.Strings[listbox1.ItemIndex];<br>&nbsp; &nbsp; &nbsp; p:=pos('##',tmp)+2;<br>&nbsp; &nbsp; &nbsp; showmessage(inttostr(p));<br>&nbsp; &nbsp; &nbsp;idid:=strtoint(copy(tmp,p,length(tmp)-p));<br>&nbsp; &nbsp; &nbsp;caption:=inttostr(idid);<br>&nbsp; &nbsp; &nbsp;ph:=OpenProcess(PROCESS_TERMINATE,boolean(0),idid);<br>&nbsp; &nbsp; &nbsp;GetExitCodeProcess(ph,a);<br>&nbsp; &nbsp; &nbsp; ret:=TerminateProcess(ph,a);<br>&nbsp; &nbsp; &nbsp; if not ret then showmessage('can not kill it');<br>&nbsp; &nbsp; &nbsp; closehandle(ph);<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br>close;<br>end;<br><br>end.<br>[8D]可能不能调试,自己改。<br>
 
顶部