相关疑难解决方法(0)

使用delphi从PID获取完整路径

我需要从PID获得完整路径.

我已经检查了这个问题C++ Windows - 如何从其PID获取进程路径 ,我编写了以下代码:

 function GetFullPathFromPID(PID: DWORD): string;
 var
    hProcess: THandle;
    ModName : Array[0..MAX_PATH + 1] of Char;
 begin
   Result:='';
    hProcess := OpenProcess(PROCESS_ALL_ACCESS,False, PID);
    try
      if hProcess <> 0 then
       if GetModuleFileName(hProcess, ModName, Sizeof(ModName))<>0 then
         Result:=ModName
        else
         ShowMessage(SysErrorMessage(GetLastError));
    finally
     CloseHandle(hProcess);
    end;
 end;
Run Code Online (Sandbox Code Playgroud)

但总是返回此消息:

指定的模块无法找到

如何从PID中获取完整路径?

delphi delphi-xe

11
推荐指数
1
解决办法
1万
查看次数

为什么我在64位Windows 8上从GetModuleFileNameEx中得到废话?

我有这个

function NazwaProcesu(const uchwyt: Thandle): string;
var
  pid: DWORD;
  hProcess: Thandle;
  sciezka: array [0..MAX_PATH - 1] of char;
begin
  GetWindowThreadProcessId(uchwyt, pid);
  hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, FALSE, pid);
  if hProcess <> 0 then
    try
      GetModuleFileNameEx(hProcess, 0, sciezka, MAX_PATH)
    finally
      Result := sciezka;
      CloseHandle(hProcess);
    end;
end;
Run Code Online (Sandbox Code Playgroud)

在Windows 7 32位没有问题.在Win 8 x64上我有这个:

在此输入图像描述

我想,最后3个条目应该是explorer.exe.感谢帮助.

delphi winapi 32bit-64bit

4
推荐指数
1
解决办法
2295
查看次数

标签 统计

delphi ×2

32bit-64bit ×1

delphi-xe ×1

winapi ×1