How can I get the current instance's executable file name from native win32 C++ app?

You can do this via the GetModuleFileName function.

TCHAR szFileName[MAX_PATH];

GetModuleFileName(NULL, szFileName, MAX_PATH)

GetCurrentProcess, then QueryFullProcessImageName

Other answers are better for your own process - this is preferred for remote ones. Per the docs:

To retrieve the module name of the current process, use the GetModuleFileName function with a NULL module handle. This is more efficient than calling the GetProcessImageFileName function with a handle to the current process.

To retrieve the name of the main executable module for a remote process in win32 path format, use the QueryFullProcessImageName function.


See GetModuleFileName()

Tags:

C++

Winapi