如何通过某个程序的句柄得到其路径,能不能实现,如何实现?请帮忙给个实现代码,谢谢了

解决方案 »

  1.   

    function GetModuleMainFileName(ProcessID: THandle;
      EXE_Name, ModuleMainFileName:PChar; iLen: Integer): Integer;
    //获得进程模块主文件名字(包含目录)
    var
    ModuleList :Thandle;
      pm :TMODULEENTRY32;
    begin
    Result := 0;
    ModuleList := CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, processID);
      try
    pm.dwSize := sizeof(TMODULEENTRY32);
    if not module32first(ModuleList, pm) then Exit;    if AnsiCompareText(Trim(pm.szModule), EXE_Name) = 0 then
        begin
         Result := length(ANSIString(pm.szexepath));
        if (ModuleMainFileName <> nil) and (iLen > 0) then
        StrLCopy(ModuleMainFileName, pm.szexepath, iLen);
          Exit;
        end;
    while module32next(ModuleList, pm) do
        begin
        if AnsiCompareText(Trim(pm.szModule), EXE_Name) = 0 then
         begin
         Result := length(ANSIString(pm.szexepath));
         if (ModuleMainFileName <> nil) and (iLen > 0) then
        StrLCopy(ModuleMainFileName, pm.szexepath, iLen);
          Exit;
        end;
        end;
      finally
    CloseHandle(ModuleList);
      end;
    end; // ModuleEnum
      

  2.   

    function GetModuleName(Module: HMODULE): string;