Module List Demo

unit ML_Unit;
interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, TlHelp32;
type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1 : TForm1;

implementation
var
  Form1 : TForm1;

implementation
{$R *.DFM}
procedure Module32List(S : TStrings);
var
 Module32 : TModuleEntry32;
 SS       : THandle;
 Next     : Bool;
begin
 //
 Module32.dwSize := SizeOf(TModuleEntry32);
 //
 SS := CreateToolHelp32Snapshot(TH32CS_SNAPMODULE, 0);
 //
 If Module32First(SS, Module32) then
  begin
 //
   S.Add(Module32.szExePath);
   Repeat
 //
    Next := Module32Next(SS, Module32);
 //
    If Next Then S.Add(Module32.szExePath);
   Until Not Next;
  end;
  CloseHandle(SS);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
 //
 Module32List(ListBox1.Items);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
 //
 ListBox1.Items.Clear;
 //
 Module32List(ListBox1.Items);
end;
end.