Tân Dương Đình Tân Dương Đình - 1 year ago 86
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download