S
sds
Unregistered / Unconfirmed
GUEST, unregistred user!
想通过循环找出已运行的“计算器”程序,并关闭其进程,<br>下面是我的程序,就是调试不好,请求帮助!<br><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> TForm1 = class(TForm)<br> Button1: TButton;<br> ListBox1: TListBox;<br> procedure Button1Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>type TProcessInfo = Record<br> ExeFile : String;<br> ProcessID : DWORD;<br> end;<br> pProcessInfo = ^TProcessInfo;<br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>p : pProcessInfo;<br>ContinueLoop:BOOL;<br>FSnapshotHandle:THandle;<br>FProcessEntry32:TProcessEntry32;<br>n:integer;<br>begin<br>n:=1;<br>FSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);<br> FProcessEntry32.dwSize:=Sizeof(FProcessEntry32);<br> ContinueLoop:=Process32First(FSnapshotHandle,FProcessEntry32);<br> while integer(ContinueLoop)<>0 do<br> begin<br> New(p);<br> p.ExeFile:= FProcessEntry32.szExeFile;<br> ListBox1.Items.Add(inttostr+')'+inttostr(FProcessEntry32.th32ProcessID)+' * '+p.ExeFile);<br> inc;<br> if p.ExeFile='C:/WINDOWS/CALC.EXE' THEN TerminateProcess(FSnapshotHandle,0);<br> ContinueLoop:=Process32Next(FSnapshotHandle,FProcessEntry32);<br> end;<br>end;<br><br>end.