Tân Dương Đình Tân Dương Đình - 8 days ago 5
C++ Question

GetModuleFileName dose not return really the path of Executable file

I am coding a program as service using c++, when I test it as a normal program, function

GetCurrentDirectory
return really path. But when I try to install my program as service,
GetCurrentDirectory
instead return real path, it return C:\Windows\System32\

How can I fix it, Thank you
(I hope you understand me)

Answer

Working directory for Windows services is always %WINDIR%\System32.

To get directory, where your executable resides, simply call GetModuleFileName with NULL for hModule argument, and manually strip executable name.

Comments