GetFileInformationByHandleEx
with option FileNameInfo
returns the current path, sans the drive designator, on the current device, when the running executable is moved within that device. To use this you apparently need to have opened the file for reading at program start up (before it’s moved). To get the executable’s path at startup you can use GetModuleFileName
.