uses
TlHelp32;
procedure TForm1.FormCreate(Sender: TObject);
var
Pname: string;
I, Pid: DWORD;
Prc: TProcessEntry32;
modu: TModuleEntry32;
hModu, hand32: THandle;
Node: TTreeNode;
begin
try
i := 0;
hand32 := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
Prc.dwSize := SizeOf(Prc);
if Process32First(hand32, prc) then
begin
Pname := string(Prc.szExeFile);
Pid := Prc.th32ProcessID;
node := tv1.Items.Add(nil, Pname);
Inc(i);
begin
hModu := CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, Pid);
Modu.dwSize := SizeOf(Modu);
if Module32First(hModu, modu) then
tv1.Items.AddChild(Node, modu.szExePath);
while Module32Next(hModu, modu) do
tv1.Items.AddChild(Node, modu.szExePath);
end;
while process32next(hand32, prc) do
begin
inc(i);
Pname := string(Prc.szExeFile);
Pid := Prc.th32ProcessID;
node := tv1.Items.Add(nil, Pname);
begin
hModu := CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, Pid);
Modu.dwSize := SizeOf(Modu);
if Module32First(hModu, modu) then
while Module32Next(hModu, modu) do
tv1.Items.AddChild(Node, modu.szExePath);
end;
end;
ShowMessage(IntToStr(i));
end;
finally
CloseHandle(hand32);
CloseHandle(hModu);
end;
end;