views:

900

answers:

2

How can I get the file name of process from a process handle? I'm using Win32 C++ (Visual C++ Express Edition).

Thanks.

+4  A: 

The GetProcessImageFileName function retrieves the name of the executable file for the specified process handle (WinXP, Server 2k3 or later), as does QueryFullProcessImageName for Vista and 2k8 or later.

Steve Gilham
+4  A: 

Call GetModuleFileNameEx. Available as of Windows 2000.

DWORD WINAPI GetModuleFileNameEx(
  __in      HANDLE hProcess,
  __in_opt  HMODULE hModule,
  __out     LPTSTR lpFilename,
  __in      DWORD nSize
);

Use NULL for the second parameter to get the name of the EXE file.

Rob Kennedy
Thanks, that's exactly what I needed.