进程枚举
unit Unit1;interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls,TlHelp32 ;
type
TForm1 = class(TForm)
lst1: TListBox;
tmr1: TTimer;
procedure tmr1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.tmr1Timer(Sender: TObject);
var
prophoto:THandle ;
openpro:ProcessEntry32;
bfirst:Boolean;
begin
lst1.Clear;
prophoto := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
openpro.dwSize := SizeOf(openpro);
bfirst:=Process32First(prophoto,openpro);
while bfirst <> False do
begin
lst1.Items.Add(openpro.szExeFile + ' PID : ' +inttostr(openpro.th32ProcessID));
bfirst:=Process32Next(prophoto,openpro);
end;
CloseHandle(prophoto);
end;
end. 来学习~ 关闭快照对象用CloseToolhelp32Snapshot, 我记得别人跟我说用CloseHandle不好... CloseHandle用对地方的话没问题,不过好多时候是在需要句柄的前面关闭掉了,那就爽歪歪了 代码写的丑,希望姐姐多多关照··· unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls,TlHelp32 ;
type
TForm1 = class(TForm)
lst1: TListBox;
tmr1: TTimer;
procedure tmr1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.tmr1Timer(Sender: TObject);
var
prophoto:THandle ;
openpro:ProcessEntry32;
bfirst:Boolean;
begin
lst1.Clear;
prophoto := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
openpro.dwSize := SizeOf(openpro);
bfirst:=Process32First(prophoto,openpro);
while bfirst <> False do
begin
lst1.Items.Add(openpro.szExeFile + ' PID : ' +inttostr(openpro.th32ProcessID));
bfirst:=Process32Next(prophoto,openpro);
end;
CloseHandle(prophoto);
end;
end.
页:
[1]