精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>● Delphi>>其他>>Re: 请问:如何获得进程列表?

主题:Re: 请问:如何获得进程列表?
发信人: tiyi@GZ()
整理人: teleme(2001-08-07 13:22:36), 站内信件

标  题: Re: 请问:如何获得进程列表?
发信站: 网易虚拟社区 (Thu Aug 10 09:45:29 2000), 站内信件

(注意uses TLHelp32) 
然后 
var lppe: TProcessEntry32; 
found : boolean; 
Hand : THandle; 
begin 
Hand := CreateToolhelp32Snapshot(TH32CS_SNAPALL,0); 
found := Process32First(Hand,lppe); 
while found do 
begin 
ListBox.Items.Add(StrPas(lppe.szExeFile));//列出所有进程。 
found := Process32Next(Hand,lppe); 
end; 
end; 

///////////////////////////////////////////////////// 
uses ... TLHelp32, ... 

type 
TForm1 = class(TForm) 
... 
end; 

var 
Form1: TForm1; 
l : Tlist; ////返回的东东在"L"这个TList中。 

type 
TProcessInfo = Record 
ExeFile : String; 
ProcessID : DWORD; 
end; 
pProcessInfo = ^TProcessInfo; 

implementation 

{$R *.DFM} 

procedure TForm1.FormCreate(Sender: TObject); 
var p : pProcessInfo; 
i : integer; 
ContinueLoop:BOOL; 
var 
FSnapshotHandle:THandle; 
FProcessEntry32:TProcessEntry32; 
begin 
l := TList.Create; 
l.Clear; 
FSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); 
FProcessEntry32.dwSize:=Sizeof(FProcessEntry32); 
ContinueLoop:=Process32First(FSnapshotHandle,FProcessEntry32); 
while integer(ContinueLoop)<>0 do 
begin 
New(p); 
p.ExeFile := FProcessEntry32.szExeFile; 
p.ProcessID := FProcessEntry32.th32ProcessID; 
l.Add(p); 
ContinueLoop:=Process32Next(FSnapshotHandle,FProcessEntry32); 
end; 
end; 

procedure TForm1.FormDestroy(Sender: TObject); 
var p : pProcessInfo; 
i : integer; 
begin 
With l do 
for i := Count - 1 DownTo 0 do 
begin p := items[i]; Dispose(p); Delete(i); end; 
end; 

... 
end. 



--
老板要跳楼!全城最低价!

※ 来源:.月光软件站 http://www.moon-soft.com.[FROM: 202.106.148.185]

[关闭][返回]