Hab den Code von Palad mal ein wenig "bereinigt" und übersichtlicher gestaltet:
Delphi-Quellcode:
uses
Tlhelp32;
procedure GetProcessList(const aProcessList: TStrings);
var
Snap: THandle;
ProcessE: TProcessEntry32;
modh: THandle;
ModuleE: TModuleEntry32;
begin
aProcessList.Clear;
Snap := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (Snap <> INVALID_HANDLE_VALUE) then
begin
try
ProcessE.dwSize := SizeOf(ProcessE);
if Process32First(Snap, ProcessE) then
Repeat
aProcessList.Add(ProcessE.szExeFile);
modh := CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, ProcessE.th32ProcessID);
if (modh <> INVALID_HANDLE_VALUE) then
begin
try
ModuleE.dwSize := SizeOf(ModuleE);
if Module32First(modh, ModuleE) then
// repeat // <- wer's gerne noch ausfuerlicher will
aProcessList.Add(ModuleE.szExePath)
// until not Module32Next(modh, ModuleE)
else
RaiseLastOSError;
finally
CloseHandle(modh);
end;
end;
Until not Process32Next(Snap, ProcessE)
else
RaiseLastOSError;
finally
CloseHandle(Snap);
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
GetProcessList(Memo1.Lines);
end;
Guido.