delphi根据进程PID获取程序所在路径的函数(用OpenProcess取得句柄,用GetModuleFileNameEx取得程序名)

时间:2023-03-08 16:54:46
delphi根据进程PID获取程序所在路径的函数(用OpenProcess取得句柄,用GetModuleFileNameEx取得程序名)

uses psapi;

{根据进程PID获取程序所在路径的函数}
function GetProcessExePath(PID: Cardinal): string;
var
pHandle: THandle;
buf: array[0..MAX_PATH] of Char;
begin
{获取进程句柄}
pHandle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, PID);
{获取进程路径}
GetModuleFileNameEx(pHandle, 0, buf, Length(buf));
CloseHandle(pHandle);
Result := buf;
end;

http://blog.csdn.net/cmdasm/article/details/9961631