请问如何在 Win2000下列出当前运行的所有程序的完整路径,而不仅仅是文件名?

解决方案 »

  1.   

    http://www.516688.net/ergong/down/dpg1f.exe
      

  2.   

    CreateToolhelp32Snapshot创建进程快照
    然后用GetModuleHandle获得模块句柄
    GetModuleName来获得进程全路径
      

  3.   

    //2000下delphi 6  测试通过unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Memo1: TMemo;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementationuses tlhelp32;
    {$R *.dfm}function get(id:int64):string;
    var lppe:TProcessEntry32;
        mo:tmoduleentry32;
        lm:thandle;
        found :boolean;
        found1:boolean;
        Hand:THandle;
        ttt_t:int64;
    begin
      result:='';
      ttt_t:=id;
      Hand:=CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
      if hand>0 then
         lppe.dwSize:= sizeof(PROCESSENTRY32);
      found:=Process32First(Hand,lppe);
      while found do
      begin
           if  ttt_t=lppe.th32ProcessID then
           begin
             lm := CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,lppe.th32ProcessID);
             if lm>0 then
                 mo.dwSize:= sizeof(MODULEENTRY32);
             found1:= module32First(lm,mo);
             if found1 then
                result:=mo.szExePath
             else
                result:='';
           end;
          found:= Process32next(Hand,lppe);
      end;
      closehandle(hand);
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    var hand:thandle;
        lppe:PROCESSENTRY32;
        found:boolean;
        v_v:string;
        tempdir:array[0..100]of char;
    begin
      memo1.Lines.BeginUpdate ;
      getwindowsdirectory(tempdir,100);
      Hand:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
      if hand>0 then
        lppe.dwSize:= sizeof(PROCESSENTRY32);
      found:=Process32First(Hand,lppe);
      while found do
      begin
        v_v:=get(lppe.th32ProcessID);
        if length(v_v)>10 then
          memo1.lines.Add(v_v)
        else
          memo1.lines.Add(string(tempdir)+'\'+strpas(lppe.szExeFile));
        found:=Process32next(Hand,lppe);
      end;
      closehandle(hand);
      memo1.Lines.EndUpdate ;
    end;end.