Unit1.pas
上传用户:psxgmh
上传日期:2013-04-08
资源大小:15112k
文件大小:1k
- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls,TLHelp32;
- type
- TForm1 = class(TForm)
- Button1: TButton;
- ListBox: TListBox;
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- //===
- //注意在编写本单元时,应注意应用"TLHelp32"单元
- //===
- procedure TForm1.Button1Click(Sender: TObject);
- var
- ProcessName : string; //进程名
- ProcessID : integer; //进程表示符
- i : integer;
- ContinueLoop:BOOL;
- FSnapshotHandle:THandle; //进程快照句柄
- FProcessEntry32:TProcessEntry32; //进程入口的结构体信息
- begin
- FSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); //创建一个进程快照
- FProcessEntry32.dwSize:=Sizeof(FProcessEntry32);
- ContinueLoop:=Process32First(FSnapshotHandle,FProcessEntry32); //得到系统中第一个进程
- //循环例举
- while ContinueLoop do
- begin
- ProcessName := FProcessEntry32.szExeFile;
- ProcessID := FProcessEntry32.th32ProcessID;
- Listbox.Items.add('应用程序名 :'+ProcessName +'#进程ID:'+ inttostr(ProcessID));
- ContinueLoop:=Process32Next(FSnapshotHandle,FProcessEntry32);
- end;
- end;
- end.