Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 967
user145586 Avatar asked Aug 02 '09 21:08

user145586


2 Answers

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.

like image 113
Rob Kennedy Avatar answered Oct 18 '22 21:10

Rob Kennedy


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.

like image 36
Steve Gilham Avatar answered Oct 18 '22 22:10

Steve Gilham