-
listing all processes
Code:
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);
ListBox2.Clear;
while Integer(ContinueLoop) <> 0 do
begin
ListBox.Items.Add(FProcessEntry32.szExeFile); //ListBox /MEMO ...
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
ListBox.Sorted := True; //Serves to sort the list of processes alphabetically
end;
putting in a MaskEdit
Code:
begin
MaskEdit.Text := listbox.Items.Strings[ListBox.itemIndex];
end;
-
-
Nice!!!
depending on the need we can simplify using.
Code:
procedure GetTasks;
var MyHandle: THandle;
Struct: TProcessEntry32;
begin
try
MyHandle:=CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS, 0);
Struct.dwSize:=Sizeof(TProcessEntry32);
if Process32First(MyHandle, Struct) then
Form1.ListBox1.Items.Add(Struct.szExeFile);
while Process32Next(MyHandle, Struct) do
Form1.ListBox1.Items.Add(Struct.szExeFile);
except on exception do
Exit;
end;
end;
Declare in uses tlhelp32.
^^