这个分我要了,下面是代码,我的程序用了一个button(button1),一个listbox(listbox1),
只有一个form(form1),程序把所有的进程找出来,然后在listbox1上显示,双击进程或者
点击按钮进程就关闭.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,TLHelp32,
StdCtrls;
type
TProcessInfo=Record
ExeFile:String;
ProcessId
WORD;
End;
ProcessInfo=^TProcessInfo;
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure ProcessList(var PList:TList);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
Current:TList;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.ProcessList(var pList:TList);
var p
rocessInfo;
ok:Bool;
ProcessListHandle:THandle;
ProcessStruct:TProcessEntry32;
Begin
PList:=TList.Create;
PList.Clear;
ProcessListHandle:=CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS,0);
ProcessStruct.dwSize:=Sizeof(ProcessStruct);
ok:=Process32First(ProcessListHandle,ProcessStruct);
while Integer(ok)<>0 do Begin
new(p);
p.ExeFile:=ProcessStruct.szExeFile;
p.ProcessID:=ProcessStruct.th32ProcessID;
PList.Add(p);
ok:=Process32Next(ProcessListHandle,ProcessStruct);
End;
End;
procedure TForm1.FormCreate(Sender: TObject);
var i:Integer;
p
RocessInfo;
begin
current:=TList.Create;
Current.Clear;
ListBox1.Clear;
ProcessList(Current);
for i:=0 to Current.Count-1 do Begin
new(p);
p:=Current.Items
;
ListBox1.Items.Add(p.ExeFile);
End;
end;
procedure TForm1.Button1Click(Sender: TObject);
var h:THandle;
aWORD;
pRocessInfo;
begin
if ListBox1.ItemIndex>=0 then Begin
p:=Current.Items[ListBox1.ItemIndex];
h:=openProcess(Process_All_Access,true,p.ProcessID);
GetExitCodeProcess(h,a);
if Integer(TerminateProcess(h,a))<>0 then Begin
ListBox1.Clear;
FormCreate(Self);
End;
End;
end;
end.
不瞒你说,我经常用这个东东关闭一些不好关闭的进程.