Delphi进程枚举

 

//用Listbox显示方法

procedure TForm1.Button1Click(Sender: TObject);
var
lppe:TProcessEntry32;
found:boolean;
Hand:THandle;
begin
      Hand:=CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);

      lppe.dwSize := Sizeof(lppe); //初始化
      found:=Process32First(Hand,lppe);
      while found do
      begin
          ListBox1.Items.Add(StrPas(lppe.szExeFile));//列出所有进程。
          found:=Process32Next(Hand,lppe);
      end;  

end;

=====================================================

procedure TForm1.Timer1Timer(Sender: TObject); //刷新进程列表
begin
listbox.Clear;
self.Button1.Click;
end;

end.

-------------------------------------------------------------------------------------------------------------

//用Listview显示方法

procedure TForm1.FormCreate(Sender: TObject);
var
found:boolean;                         //定义枚举进程所需变量
NewItem: TListItem;
FSnapshotHandle:tHANDLE;
lppe:TProcessEntry32;
Summ: Word;
begin

with listview1 do
begin
Columns.Add;
Columns.Add;
Columns.Add;
ViewStyle:=vsreport;
GridLines:=true;
columns.items[0].caption:='进程名';
columns.items[1].caption:='进程序号';
columns.items[2].caption:='进程ID';
Columns.Items[0].Width:=100;
Columns.Items[1].Width:=100;
Columns.Items[2].Width:=150;    //初始化listview
end;


ListView1.Items.BeginUpdate;
ListView1.Items.Clear;
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); //CreateToolhelp32Snapshot函数得到进程快照

lppe.dwSize := Sizeof(lppe); //初始化
found := Process32First(FSnapshotHandle, lppe); //Process32First 得到一个系统快照里第一个进程的信息
Summ := 0;
while found do
    begin
    Summ := Summ + 1;
    NewItem := ListView1.Items.Add;   //在ListView1显示
    NewItem.ImageIndex := -1;
    NewItem.Caption := ExtractFileName(lppe.szExeFile);//进程名称
    NewItem.subItems.Add(FormatFloat('00', Summ));//序号
    NewItem.subItems.Add(IntToStr(lppe.th32ProcessID));//进程ID
    found := Process32Next(FSnapshotHandle, lppe);
end;
CloseHandle(FSnapshotHandle);
ListView1.Items.EndUpdate;
self.Label1.Caption:='当前系统共有'+''+inttostr(listview1.Items.count)+''+'个进程' ;
end;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值