再来一个简单点的:
procedure TForm1.Button1Click(Sender: TObject);
var
lppe: TProcessEntry32;
found : boolean;
Hand : THandle;
begin
Hand := CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
found := Process32First(Hand,lppe);
while found do begin
ListBox1.Items.Add(StrPas(lppe.szExeFile));
found := Process32Next(Hand,lppe);
end;
end;
uses tlhelp32;
Function ListRuningExeName(ExeName:TStrings):Integer;
Var
iHandle:LongInt;
lppe:tagProcessentry32;
i:integer;
begin
i:=0;
iHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
try
try
if iHandle=-1 then Raise Exception.Create('调用失败!');
Process32First(iHandle,lppe);
While GetLastError<>ERROR_NO_MORE_FILES do
begin
inc(i);
ExeName.Add(lppe.szExeFile);
Process32Next(iHandle,lppe);
end;
except
On E:Exception do begin
Application.HandleException(E);
i:=-1;
end;
type
TForm1 = class(TForm)
ListBox1: TListBox;
BitBtn1: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
var hcurrentwindow:hwnd;
sztext:array[0..254]of char;
begin
hcurrentwindow:=getwindow(handle,gw_hwndfirst);
while hcurrentwindow <> 0 do
begin
if getwindowtext(hcurrentwindow,@sztext,255) > 0 then
listbox1.Items.Add(strpas(@sztext));
hcurrentwindow:=getwindow(hcurrentwindow,gw_hwndnext);
end;
end;