极点博客 网络软件、编程技术博客

delphi枚举进程代码

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,tlhelp32;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.Button1Click(Sender: TObject);
var
  ProcessName: string;
  ProcessID: integer;
  ListLoop: Boolean;
  FsnapShotHandle: Thandle;
  FProcessEntry32:TProcessEntry32;
begin
  Fsnapshothandle := CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS, 0);
  FProcessEntry32.dwsize := SizeOF(FProcessEntry32);
  Listloop := Process32First(FSnapshotHandle, FProcessEntry32);
  while Listloop do
  begin
    ProcessName:=FprocessEntry32.szExeFile;
    ProcessID:=FProcessEntry32.th32ProcessID;
    ListLoop := Process32Next(FSnapshotHandle, FprocessEntry32);
    end;
    if ProcessName='elementclient.exe' then
    begin
    listbox1.Items.Add(ProcessNAme+' PID: '+inttostr(processid));
      end;
CloseHandle(FSnapshotHandle);
end;


end.

标签: delphi

作者:xtpyeihc 分类:先前文章 浏览:173 评论:0
留言列表
发表评论
来宾的头像