user145586
user145586

Reputation: 1097

Win32API - How to get file name of process from process handle?

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

Thanks.

Upvotes: 7

Views: 20909

Answers (2)

Rob Kennedy
Rob Kennedy

Reputation: 163357

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.

Upvotes: 14

Steve Gilham
Steve Gilham

Reputation: 11277

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.

Upvotes: 11

Related Questions