CreateToolhelp32Snapshot的delphi使用实例:
uses TLHelp32;
procedure TForm1.Button1Click(Sender: TObject);
var
ProcessName: string;
ProcessID: integer;
ListLoop: Boolean;
FsnapShotHandle: Thandle;
FProcessEntry32: TProcessEntry32;
begin
Fsnapshothandle := CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwsize := SizeOF(FProcessEntry32);
Listloop := Process32First(FSnapshotHandle, FProcessEntry32);
while Listloop do begin
ProcessName := FprocessEntry32.szExeFile;
ProcessID := FProcessEntry32.th32ProcessID;
// 我写到列表框中了,你可以根据需要自己改
listbox1.Items.Add('Process NAME:' + ProcessNAme);
ListLoop := Process32Next(FSnapshotHandle, FprocessEntry32);
end;
end;