新建窗体,加button,listbox,timer三个组件
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,tlhelp32, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
i:longbool;
ss:string;
had:thandle;
bl:boolean;
tp32:tprocessentry32;
begin
ss:=listbox1.Items.Strings[listbox1.Itemindex];
had:=createtoolhelp32snapshot(th32cs_snapprocess,0);
tp32.dwSize:=sizeof(tp32);
bl:=process32first(had,tp32);
while integer(bl)<>0 do
begin
if (tp32.szExeFile)=ss then
begin
i:=TerminateProcess(OpenProcess(PROCESS_TERMINATE, BOOL(0),tp32.th32ProcessID), 0);
if integer(i)<>0 then
showmessage('关闭'+ss+'成功')
else
showmessage('关闭'+ss+'失败');
break;
end;
bl:=process32next(had,tp32);
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
had:thandle;
procstruct:TProcessEntry32;
bl:Boolean;
begin
timer1.Interval:=3500;
listbox1.Items.Clear;
had:=createtoolhelp32snapshot(Th32cs_snapprocess,0);
procStruct.dwSize:=sizeof(procstruct);
bl:=process32first(had,procstruct);
while integer(bl)<>0 do
begin
listbox1.Items.add(ProcStruct.szExeFile);
bl:=process32next(had,ProcStruct);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
had:thandle;
procstruct:TProcessEntry32;
bl:Boolean;
begin
listbox1.Items.Clear;
had:=createtoolhelp32snapshot(Th32cs_snapprocess,0);
procStruct.dwSize:=sizeof(procstruct);
bl:=process32first(had,procstruct);
while integer(bl)<>0 do
begin
listbox1.Items.add(ProcStruct.szExeFile);
bl:=process32next(had,ProcStruct);
end;
end;
end.
软件下载:http://www.cnitblog.com/Files/shuyezi122/关闭进程.rar
此程序没有解释,如不明白请阅读我另外两篇文章:
http://www.cnitblog.com/shuyezi122/articles/51301.html
http://www.cnitblog.com/shuyezi122/archive/2008/11/11/51337.html
posted on 2008-11-13 18:45
小叶子 阅读(370)
评论(0) 编辑 收藏 引用 所属分类:
delphi与电脑知识