GetCurrentDirectory 并没有真正返回可执行文件的路径 [英] GetCurrentDirectory does not really return the path of the executable file

查看:36
本文介绍了GetCurrentDirectory 并没有真正返回可执行文件的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 C++ 将程序编码为服务,当我将其作为普通程序进行测试时,函数 GetCurrentDirectory 返回正确的路径.但是当我尝试将我的程序安装为服务时,GetCurrentDirectory 返回 C:\Windows\System32 而不是可执行文件的路径.

I am coding a program as service using c++, when I test it as a normal program, the function GetCurrentDirectory returns the correct path. But when I try to install my program as service, GetCurrentDirectory returns C:\Windows\System32 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?

推荐答案

Windows 服务的工作目录始终为 %WINDIR%\System32.

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

要获取可执行文件所在的目录,只需调用 GetModuleFileNamehModule 参数设置为 NULL,并手动去除可执行文件名称.

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

这篇关于GetCurrentDirectory 并没有真正返回可执行文件的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆