怎样取得指定进程的全路径?
当前系统中存在两个同名的进程它们都是EXPLORER.EXE,其中有一个是系统的,而有一个可能是病毒,
我在程序中应该怎样编程让它能识别出来,那个是真,那个是假呢?我初步的想法是检查它们的路径,如果路径是X:\windows\EXPLORER.EXE,
那么它就是真的,其余都是假的现在我想分别得到这两个进程的路径,大虾,请帮助小弟一下吧!

解决方案 »

  1.   

    (注意uses TLHelp32)然后var lppe: TProcessEntry32;found : boolean;Hand : THandle;beginHand := CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);found := Process32First(Hand,lppe);while found dobeginListBox.Items.Add(StrPas(lppe.szExeFile));//列出所有进程。found := Process32Next(Hand,lppe);end;end;/////////////////////////////////////////////////////uses ... TLHelp32, ...typeTForm1 = class(TForm)...end;varForm1: TForm1;l : Tlist; ////返回的东东在"L"这个TList中。typeTProcessInfo = RecordExeFile : String;ProcessID : DWORD;end;pProcessInfo = ^TProcessInfo;implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);var p : pProcessInfo;i : integer;ContinueLoop:BOOL;varFSnapshotHandle:THandle;FProcessEntry32:TProcessEntry32;beginl := TList.Create;l.Clear;FSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);FProcessEntry32.dwSize:=Sizeof(FProcessEntry32);ContinueLoop:=Process32First(FSnapshotHandle,FProcessEntry32);while integer(ContinueLoop)<>0 dobeginNew(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;beginWith l dofor i := Count - 1 DownTo 0 dobegin p := items[i]; Dispose(p); Delete(i); end;end;...end.
      

  2.   

    FProcessEntry32.szExeFile;
    这样子不行的,它返回的不是进程的路径
      

  3.   

    给你个函数
    function EnabledDebugPrivilege(const bEnabled: Boolean):Boolean;
    var
        hToken: THandle;
        tp: TOKEN_PRIVILEGES;
        a: DWORD;
    const
        SE_DEBUG_NAME = 'SeDebugPrivilege';
    begin
        Result:=False;
        //打开当前Process的令牌
        if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, hToken)) then
        begin
            //调整令牌的权限,加上权限(SE_DEBUG_NAME)
            tp.PrivilegeCount :=1;
            LookupPrivilegeValue(nil,SE_DEBUG_NAME ,tp.Privileges[0].Luid);
            if bEnabled then
                tp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED
            else
                tp.Privileges[0].Attributes := 0;
            a:=0;
            AdjustTokenPrivileges(hToken,False,tp,SizeOf(tp),nil,a);
            Result:= GetLastError = ERROR_SUCCESS;
            CloseHandle(hToken);
        end;
    end;Function GetProcessFullPath(Name:String):String;
    Var
        Hd,Hs:THandle;
        ParentStr:String;
        pLps:PModuleEntry32;
        Lps:TModuleEntry32;
        Lp:TProcessEntry32;
        Hds:THandle;
        S,F:Cardinal;
    begin
        EnabledDebugPrivilege(true);
        Try
            Lp.dwSize:=sizeof(TProcessEntry32);
            Hd:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
            if Process32First(Hd,Lp) then
                Repeat
                    Try
                        ParentStr:=UpperCase(StrPas(Lp.szExeFile));
                        if ParentStr=UpperCase(Name) then
                        begin
                            Hs:=CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,Lp.th32ProcessID);
                            Lps.dwSize:=SizeOf(TModuleEntry32);
                            if Module32First(Hs,Lps) then
                            begin
                                Result:=Lps.szExePath;
                            end
                            else
                                Result:='';
                            CloseHandle(Hs);
                            break;
                        end;
                    Except
                    end;
                Until Process32Next(Hd,Lp)=False;
            CloseHandle(Hd);
        Finally
            EnabledDebugPrivilege(false);
        end;
    end;