RSS订阅 | 匿名投稿
您的位置:网站首页 > 进程 > 正文

delphi枚举进程信息

作者:admin 来源:未知 日期:2010/5/9 14:31:34 人气: 标签:

源代码:
---------------------------------------------------------

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,tlHelp32, StdCtrls;
type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure CreateProList;
  *******
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Halt;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  CreateProList;
end;

procedure TForm1.CreateProList;
var
  hSnap:THandle;
  ps:TProcessEntry32;
  b:BOOL;
begin
  hSnap:=tlHelp32.CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
  { TODO -o猪悟能 : 必须把dwsize先赋值为Sizeof(processEntry32),否则取不到信息 }
  ps.dwSize:=SizeOf(TprocessEntry32);
  b:=tlHelp32.Process32First(hSnap,ps);
  //进程ID----进程的可执行文件名称
  ListBox1.Items.Add(IntToHex(ps.th32ProcessID,8)+
    '----'+ ps.szExeFile);
  if b then
  begin
     while tlHelp32.Process32Next(hSnap,ps) do
       ListBox1.Items.Add(IntToHex(ps.th32ProcessID,8)+
       '----'+ps.szExeFile);
  end;

  CloseHandle(hSnap);
end;

end.


读完这篇文章后,您心情如何?
0
0
0
0
0
0
0
0
本文网址: