呵呵,举手之劳,转贴: (注意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.
(注意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.
完整的: 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. /////////////////////////////////// procedure TForm1.Button1Click(Sender: TObject); {Places the modulenames of the running/minimized tasks into a listbox } var pTask : pTaskEntry; {requires Uses ToolHelp} Task : bool; Pstr : array [0..79] of Char; Str : string[80]; byt_j : byte; begin ListBox1.Clear; GetMem(pTask, SizeOf(TTaskEntry)); {Reserve memory for TaskEntry} pTask^.dwSize:=SizeOf(TTaskEntry);
byt_j:=0; {Set up a counter for number of tasks} Task:=TaskFirst(pTask); {Find first task} While task do begin inc(byt_j); {count number of different tasks} Str:=StrPas(pTask^.szModule); {Convert PStr into Pascal string} Listbox1.Items.Add(str); {Store Pascal string into listbox} task:=taskNext(pTask); {Check for next possible task} end; Label1.Caption:=IntToStr(byt_j)+ ' tasks found'; {Show counter} end;
(注意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.
然后
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.
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.
///////////////////////////////////
procedure TForm1.Button1Click(Sender: TObject);
{Places the modulenames of the running/minimized tasks into a listbox }
var
pTask : pTaskEntry; {requires Uses ToolHelp}
Task : bool;
Pstr : array [0..79] of Char;
Str : string[80];
byt_j : byte;
begin
ListBox1.Clear;
GetMem(pTask, SizeOf(TTaskEntry)); {Reserve memory for TaskEntry}
pTask^.dwSize:=SizeOf(TTaskEntry);
byt_j:=0; {Set up a counter for number of tasks}
Task:=TaskFirst(pTask); {Find first task}
While task do
begin
inc(byt_j); {count number of different tasks}
Str:=StrPas(pTask^.szModule); {Convert PStr into Pascal string}
Listbox1.Items.Add(str); {Store Pascal string into listbox}
task:=taskNext(pTask); {Check for next possible task}
end;
Label1.Caption:=IntToStr(byt_j)+ ' tasks found'; {Show counter}
end;