来自:tinytao, 时间:2001-6-7 12:26:00, ID:557402 <br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> Grids, StdCtrls, ExtCtrls,<br> tlhelp32; //记得加这个<br><br>type<br> Tprocessinfo=record<br> ExeFile:string;<br> ProcessId
Word;<br> end;<br> Processinfo=^Tprocessinfo;<br><br> TForm1 = class(TForm)<br> Button1: TButton;<br> Button2: TButton;<br> Timer1: TTimer;<br> StringGrid1: TStringGrid;<br> procedure FormCreate(Sender: TObject);<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> procedure Timer1Timer(Sender: TObject);<br> procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> procedure FormActivate(Sender: TObject);<br> private<br> { Private declarations }<br> procedure Initialize;<br> procedure RefreshList; //刷新<br> procedure ProcessList(var PList:TList); //得进程列表<br> function KillCourse(Item:integer):String; //杀进程<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.FormCreate(Sender: TObject);<br>var<br> temp:integer;<br>begin<br> //这两句可不要,第一句,不在任务栏显示<br> //第二句屏蔽Ctrl+alt+Del<br> SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);<br> SystemParametersInfo(Spi_screensaverrunning,1,@temp,0);<br><br> Current:=TList.Create;<br> Initialize;<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>var<br> temp:integer;<br>begin<br> Current.Free;<br> //恢复Ctrl+alt+Del<br> SystemParametersInfo(Spi_screensaverrunning,0,@temp,0);<br>end;<br><br>procedure TForm1.FormActivate(Sender: TObject);<br>begin<br> //这句就看你了,调试就不要加了<br>// ShowWindow(Handle, SW_HIDE);<br>end;<br><br>procedure TForm1.Initialize;<br>begin<br> StringGrid1.FixedCols:=0;<br> StringGrid1.FixedRows:=1;<br> StringGrid1.ColCount:=3;<br> StringGrid1.Options:=[goFixedVertLine,goFixedHorzLine,goRangeSelect,goRowSelect];<br> StringGrid1.ColWidths[0]:=70;<br> StringGrid1.ColWidths[1]:=100;<br> StringGrid1.ColWidths[2]:=StringGrid1.Width-200;<br> StringGrid1.DefaultRowHeight:=14;<br> StringGrid1.Cells[0,0]:='ID';<br> StringGrid1.Cells[1,0]:='进程';<br> StringGrid1.Cells[2,0]:='路径';<br><br> RefreshList;<br>end;<br><br>procedure TForm1.ProcessList(var PList: TList);<br>var<br> p
rocessinfo;<br> Ok:Bool;<br> ProcessListHandle:Thandle;<br> Processstruct:TProcessentry32;<br>begin<br> PList.Clear;<br> ProcessListHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);<br> Processstruct.dwSize:=sizeof(Processstruct);<br> ok:=process32first(ProcessListHandle,processstruct);<br> while Ok do<br> 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.RefreshList;<br>var<br> i:integer;<br> p
rocessinfo;<br>begin<br> ProcessList(current);<br><br> StringGrid1.RowCount:=current.Count+1;<br> for i:=1 to StringGrid1.RowCount do<br> begin<br> StringGrid1.Cells[0,i]:='';<br> StringGrid1.Cells[1,i]:='';<br> StringGrid1.Cells[2,i]:='';<br> end;<br><br> for i:=1 to current.Count do<br> begin<br> p:=current.Items[i-1];<br> StringGrid1.Cells[0,i]:=IntToHex(p.ProcessId,8);<br> StringGrid1.Cells[1,i]:=ExtractFileName(P.ExeFile);<br> StringGrid1.Cells[2,i]:=ExtractFilePath(p.ExeFile);<br> end;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> str:string;<br>begin<br> if StringGrid1.Selection.Top>0 then<br> begin<br> str:=KillCourse(StringGrid1.Selection.Top-1);<br> if str<>'' then<br> Application.MessageBox(Pchar(Str),'杀杀杀!',64);<br> RefreshList;<br> end;<br>end;<br><br>function TForm1.KillCourse(Item: integer): String;<br>var<br> h:Thandle;<br> a
Word;<br> p
rocessInfo;<br> Name:string;<br>begin<br> Result:='';<br> try<br> p:=current.Items[Item];<br> Name:=ExtractFileName(P.ExeFile);<br> h:=OpenProcess(Process_All_Access,True,p.ProcessId);<br> GetExitCodeProcess(h,a);<br> if TermInateprocess(h,a) then<br> Result:=Name;<br> finally<br> end;<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br> RefreshList;<br>end;<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>var<br> i:integer;<br> p
rocessInfo;<br>begin<br> ProcessList(current);<br> i:=0;<br> repeat<br> begin<br> p:=current.Items
;<br> if Pos('你要杀的',P.ExeFile)>0 then //注意:不要把你的系统也杀了<br> begin<br> KillCourse(i);<br> ProcessList(current);<br> i:=-1;<br> end;<br> i:=i+1;<br> end;<br> until I=current.Count;<br>end;<br><br>end.<br><br> <br>