怎样用api来枚举当前运行的所有程序?

解决方案 »

  1.   

    新年快乐!羊年发洋财!uses tlhelp32;
    Function ListRuningExeName(ExeName:TStrings):Integer;
    Var
        iHandle:LongInt;
        lppe:tagProcessentry32;
        i:integer;
    begin
        i:=0;
        iHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
        try
          try
            if iHandle=-1 then    Raise Exception.Create('调用失败!');
            Process32First(iHandle,lppe);
            While GetLastError<>ERROR_NO_MORE_FILES do
            begin
                inc(i);
                ExeName.Add(lppe.szExeFile);
                Process32Next(iHandle,lppe);
            end;
          except
           On E:Exception do begin
            Application.HandleException(E);
            i:=-1;
           end;      end;
        finally
            CloseHandle(iHandle);
            Result:=i;
        end;
    end;
      

  2.   

    新年快乐!羊年发洋财!再来一个简单点的:
    procedure TForm1.Button1Click(Sender: TObject);
    var
      lppe: TProcessEntry32;
      found : boolean;
      Hand : THandle;
    begin
      Hand := CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
      found := Process32First(Hand,lppe);
      while found do begin
        ListBox1.Items.Add(StrPas(lppe.szExeFile));
        found := Process32Next(Hand,lppe);
      end;
    end;
      

  3.   

    nit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Buttons;type
      TForm1 = class(TForm)
        ListBox1: TListBox;
        BitBtn1: TBitBtn;
        procedure BitBtn1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.BitBtn1Click(Sender: TObject);
    var hcurrentwindow:hwnd;
        sztext:array[0..254]of char;
    begin
      hcurrentwindow:=getwindow(handle,gw_hwndfirst);
      while hcurrentwindow <> 0 do
        begin
          if getwindowtext(hcurrentwindow,@sztext,255) > 0 then
            listbox1.Items.Add(strpas(@sztext));
            hcurrentwindow:=getwindow(hcurrentwindow,gw_hwndnext);
        end;    
    end;end.
      

  4.   

    enumwindowchild,
    回掉函数可以一一列举所有窗口!