



Algum dia você já precisou verificar se algum processo estava ativo no Windows,
veja que podemos listar facilmente utilizando alguns métodos da unit
Tlhelp32.
Abaixo veja um exemplo em Delphi XE 8 compilado para 64 bits.
Trata-se de um ListBox e um botão:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; type TForm1 = class(TForm) ListBox1: TListBox; Button1: TButton; procedure Button1Click(Sender: TObject); private public { Public declarations } end; procedure GetOpenProcess(List : TStrings); var Form1: TForm1; implementation {$R *.dfm} uses Tlhelp32; { TForm1 } procedure GetOpenProcess(List : TStrings); const PROCESS_TERMINATE = $0001; var ContinueLoop: BOOL; FSnapshotHandle: THandle; FProcessEntry32: TProcessEntry32; begin FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); FProcessEntry32.dwSize := SizeOf(FProcessEntry32); ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32); List.Clear; while Integer(ContinueLoop) <> 0 do begin List.Add(FProcessEntry32.szExeFile); ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32); end; CloseHandle(FSnapshotHandle); end; procedure TForm1.Button1Click(Sender: TObject); begin GetOpenProcess(ListBox1.Items); { Ordenando a lista dos processos por ordem alfabética } ListBox1.Sorted := True; end; end. |