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