Tân Dương Đình Tân Dương Đình - 6 months ago 27
C++ Question

GetCurrentDirectory does not really return the path of the executable file

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

returns the correct path. But when I try to install my program as service,
instead of the path of the executable.

How can I get the path of my executable file in a way that will work for a service?


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.