我需要从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中获取完整路径?
我有这个
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.感谢帮助.