Delphi获取系统进程和进程ID,Listview实现:
var Form1: TForm1; Summ: Word; implementation {$R *.dfm} procedure TForm1.N2Click(Sender: TObject); var ContinueLoop: BOOL; NewItem: TListItem; begin ListView1.Items.BeginUpdate; ListView1.Items.Clear; FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); //CreateToolhelp32Snapshot函数得到进程快照 FProcessEntry32.dwSize := Sizeof(FProcessEntry32); //初始化 ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32); //Process32First 得到一个系统快照里第一个进程的信息 Summ := 0; while ContinueLoop do begin Summ := Summ + 1; NewItem := ListView1.Items.Add; //在ListView1显示 NewItem.ImageIndex := -1; NewItem.Caption := ExtractFileName(FProcessEntry32.szExeFile);//进程名称 NewItem.subItems.Add(FormatFloat('00', Summ));//序号 NewItem.subItems.Add(IntToStr(FProcessEntry32.th32ProcessID));//进程ID ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32); end; CloseHandle(FSnapshotHandle); ListView1.Items.EndUpdate; end;
|
请发表评论