怎样编写如同任务管理器一样列示所有进程名(100分)

  • 主题发起人 CashChin
  • 开始时间
C

CashChin

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样编写如同任务管理器一样列示所有进程名,能在WIN98和WINNT中运行。
 
win98和winnt中要用不同的函数,用helptools.pas里的函数Process32First()和Process32Next()
 
下面的这段代码就可以完全实现你的要求
俺现在太穷啦,快点给分吧

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,shellapi, ExtCtrls, StdCtrls, ScktComp;

type
TProcessInfo=Record //取得系统运行的进程列表
ExeFile:String;
ProcessId:DWORD;
end;
ProcessInfo=^TProcessInfo;




procedure TForm1.Button1Click(Sender: TObject);
var
ProcessListHandle:THandle;
h:THandle;
a:DWORD;
p:pRocessInfo;
ok:Bool;
ProcessStruct:TProcessEntry32;
Begin
ProcessListHandle:=CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS,0);
ProcessStruct.dwSize:=Sizeof(ProcessStruct);
ok:=Process32First(ProcessListHandle,ProcessStruct);
while Integer(ok)<>0 do Begin
new(p);
p.ExeFile:=ProcessStruct.szExeFile; //Process Name
p.ProcessID:=ProcessStruct.th32ProcessID; //Process ID
// listbox1.Items.Add(p.exefile); //add Process Name to Listbox1
ok:=Process32Next(ProcessListHandle,ProcessStruct);
if p.ExeFile='word.exe' then begin //if Process='word.exe' then TerminateProcess
h:=openProcess(Process_All_Access,true,p.ProcessId);
GetExitCodeProcess(h,a);
if Integer(TerminateProcess(h,a))<>0 then
try terminateprocess(h,a); except end;
end;
end;
end;
 
如何使用PSAPI.Pas对系统进程进行列举。
 
顶部