This program will allow you to display processes that are running on your PC. 1 2 uses 3 tlhelp32; 4 5 type 6 TForm1 = class(TForm) 7 Button1: TButton; 8 lvView: TListView; 9 procedure Button1Click(Sender: TObject); 10 private 11 { Private declarations } 12 procedure ViewProccess; 13 public 14 { Public declarations } 15 end; 16 17 var 18 Form1: TForm1; 19 20 implementation 21 22 {$R *.dfm} 23 24 procedure TForm1.ViewProccess; 25 var 26 ContinueLoop: BOOL; 27 FSnapshotHandle: THandle; 28 FProcessEntry32: TProcessEntry32;//used to store proccess information that are 29 currnently running 30 sFileName:string; 31 ls:TlistItem; 32 begin 33 lvView.Clear; 34 //Takes a snapshot of the processes and the heaps, modules, and threads used by 35 the processes 36 FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); 37 38 FProcessEntry32.dwSize := Sizeof(FProcessEntry32); 39 40 //Retrieves information about the first process encountered in a system snapshot 41 ContinueLoop := Process32First(FSnapshotHandle,FProcessEntry32); 42 43 while integer(ContinueLoop) <> 0 do //stops until there is no more processes to 44 check 45 begin 46 sFileName:= UpperCase(ExtractFileName(FProcessEntry32.szExeFile)); 47 48 ls:=TlistItem.Create(lvView.items); 49 ls.Caption:=sFileName; 50 ls.SubItems.add(intTostr(FProcessEntry32.th32ProcessID)); 51 ls.SubItems.add(intTostr(FProcessEntry32.cntThreads)); 52 lvView.Items.Add; 53 lvView.Items[(lvView.items.count-1)]:=ls; 54 55 //gets the next process encountered in a system snapshot 56 ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32); 57 end; 58 59 60 CloseHandle(FSnapshotHandle); 61 end; 62 63 procedure TForm1.Button1Click(Sender: TObject); 64 begin 65 ViewProccess; 66 end; 67 68 69 70 71 72 This is the DFM text or code. 73 74 object Form1: TForm1 75 Left = 391 76 Top = 193 77 Width = 317 78 Height = 325 79 Caption = 'My Proccess Viewer' 80 Color = clBtnFace 81 Font.Charset = DEFAULT_CHARSET 82 Font.Color = clWindowText 83 Font.Height = -11 84 Font.Name = 'MS Sans Serif' 85 Font.Style = [] 86 OldCreateOrder = False 87 PixelsPerInch = 96 88 TextHeight = 13 89 object Button1: TButton 90 Left = 112 91 Top = 272 92 Width = 75 93 Height = 25 94 Caption = 'View' 95 TabOrder = 0 96 OnClick = Button1Click 97 end 98 object lvView: TListView 99 Left = 32 100 Top = 8 101 Width = 250 102 Height = 257 103 Columns = < 104 item 105 Caption = 'FileName' 106 Width = 100 107 end 108 item 109 Caption = 'ProcessID' 110 Width = 70 111 end 112 item 113 Caption = 'Threads' 114 Width = 60 115 end> 116 TabOrder = 1 117 ViewStyle = vsReport 118 end 119 end