如何枚举当前运行的所有进程?在win9x下、winnt下、win2000、winxp都能运行?分不够还可以再加!!!!

解决方案 »

  1.   

    var lppe:tprocessentry32;found:boolean;hand:thandle;
    begin
    memo1.Lines.Clear;
    hand:=createtoolhelp32snapshot(th32cs_snapall,0);
    found:=process32first(hand,lppe);
    while found do
    begin
    //showmessage('123');
    memo1.Lines.Add(strpas(lppe.szExeFile));
    found:=process32next(hand,lppe);
    end;
    end;
      

  2.   

    楼上的代码在winnt下不行!不知道在win2000下如何?
      

  3.   

    我的程序在WIN2000下编译通过,估计在WIN98、WINXP下应无问题!
      

  4.   

    使用函数VOID GetStartupInfo(LPSTARTUPINFO lpStartupInfo);来取得当前运行的进程。LPSTARTUPINFO 就是这个结构类型。
      

  5.   

    获得进程名称及进程句柄、序号。(form1里放一个ListView,设置ViewStyle为vsReport,添加3个Column。在加一个button,里面的OnClick写RunningAppList。)
    procedure RunningAppList;
    var
      WinText:array [0..255] of char;
      Handler:array [0..200] of LongInt;
      RenHWND:integer;
      Count:integer;
      RetValue:LongInt;
      WinTextLength:LongInt;
    begin
      Count:=0;
      RenHWND:=GetWindow(Form1.Handle,GW_HWNDFIRST);
      repeat
      RetValue:=GetWindowText(RenHWND,@WinText,255);
      if RetValue>0 then
      begin
        WinTextLength:=GetWindowTextLength(RenHWND);
        Form1.ListView1.Items.Add;
        Form1.ListView1.Items.Item[Count].Caption:=StrPas(@winText);
        Form1.ListView1.Items.Item[count].SubItems.Add(IntToStr(RenHWND));
        Form1.ListView1.Items.Item[count].SubItems.Add(inttostr(count));
        Handler[Count]:=RenHWND;
        Count:=count+1;
      end;
      RenHWND:=GetWindow(RenHWND,GW_HWNDNEXT);
      until RenHWND=0;
    end;
      

  6.   

    uses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls,Tlhelp32;type
      TForm1 = class(TForm)
        Edit1: TEdit;
        StaticText1: TStaticText;
        Button1: TButton;
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}
    procedure Button1Click(Sender: TObject);
    const
      PROCESS_TERMINATE=$0001;
      //进程的PROCESS_TERMINATE访问权限
    var
      ContinueLoop: BOOL;
      FSnapshotHandle: THandle;
      FProcessEntry32: TProcessEntry32;
    begin
      result:= 0;
      FSnapshotHandle := CreateToolhelp32Snapshot
                         (TH32CS_SNAPPROCESS, 0);
     //获取系统所有进程快照
      FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
      //调用Process32First前用Sizeof(FProcessEntry32)填充FProcessEntry32.dwSize
      ContinueLoop := Process32First(FSnapshotHandle,
                                     FProcessEntry32);
     //获取快照中第一个进程信息并保存到FProcessEntry32结构体中
      while integer(ContinueLoop) <> 0 do
     //循环枚举快照中所有进程信息
      begin
    form1.Memo1.Lines.Add(strpas(FProcessEntry32.szExeFile));
    ContinueLoop := Process32Next(FSnapshotHandle,FProcessEntry32);
         //查找下一个符合条件进程
      end;
    end;在WIN98、WIN2000下均可。