delphi中对于进程的操作

来源:互联网 发布:mac上能玩的格斗游戏 编辑:程序博客网 时间:2024/05/16 11:54

 

Uses Tlhelp32;//用Listbox显示方法procedure TForm1.Button1Click(Sender: TObject);varlppe:TProcessEntry32;found:boolean;Hand:THandle;begin      Hand:=CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);      lppe.dwSize := Sizeof(lppe); //初始化      found:=Process32First(Hand,lppe);      while found do      begin          ListBox1.Items.Add(StrPas(lppe.szExeFile));//列出所有进程。          found:=Process32Next(Hand,lppe);      end;  end;=====================================================procedure TForm1.Timer1Timer(Sender: TObject); //刷新进程列表beginlistbox.Clear;self.Button1.Click;end;end.-------------------------------------------------------------------------------------------------------------//用Listview显示方法procedure TForm1.FormCreate(Sender: TObject);varfound:boolean;                         //定义枚举进程所需变量NewItem: TListItem;FSnapshotHandle:tHANDLE;lppe:TProcessEntry32;Summ: Word;beginwith listview1 dobeginColumns.Add;Columns.Add;Columns.Add;ViewStyle:=vsreport;GridLines:=true;columns.items[0].caption:='进程名';columns.items[1].caption:='进程序号';columns.items[2].caption:='进程ID';Columns.Items[0].Width:=100;Columns.Items[1].Width:=100;Columns.Items[2].Width:=150;    //初始化listviewend;ListView1.Items.BeginUpdate;ListView1.Items.Clear;FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); //CreateToolhelp32Snapshot函数得到进程快照lppe.dwSize := Sizeof(lppe); //初始化found := Process32First(FSnapshotHandle, lppe); //Process32First 得到一个系统快照里第一个进程的信息Summ := 0;while found do    begin    Summ := Summ + 1;    NewItem := ListView1.Items.Add;   //在ListView1显示    NewItem.ImageIndex := -1;    NewItem.Caption := ExtractFileName(lppe.szExeFile);//进程名称    NewItem.subItems.Add(FormatFloat('00', Summ));//序号    NewItem.subItems.Add(IntToStr(lppe.th32ProcessID));//进程ID    found := Process32Next(FSnapshotHandle, lppe);end;CloseHandle(FSnapshotHandle);ListView1.Items.EndUpdate;self.Label1.Caption:='当前系统共有'+''+inttostr(listview1.Items.count)+''+'个进程' ;end;

 

原创粉丝点击