用于启动App的GetCurrentDirectory。 c ++

可能重复:
Win32:查找正在运行的进程EXE所在的目录
如何在Windows(C ++ Win32或C ++ / CLI)中获取应用程序可执行文件名?

嗨,我想让我的应用程序在statup上运行,它使用同一个目录中的一些文件。它运行良好但是当它在启动时启动时,GetCurrentDirectory是“c:\ Documents and Settings \ User \”..但我想要exe文件的实际路径。我可以用c ++获取它。 请帮我。 谢谢。

尝试使用GetModuleFileNameGetModuleFileNameEx

做这个:

 wchar_t exeDirectory[1024]; //to store the directory DWORD ret = GetModuleFileName(NULL, exeDirectory, 1024); if ( ret ) { /*the path to your EXE is stored in the variable "exeDirectory" - use it */ } 

注意我作为第一个参数传递NULL,因为MSDN说,

“如果此参数为NULL,则GetModuleFileName将检索当前进程的可执行文件的路径。”

这就是你想要的。 对?

使用argv可能:

 int main(int argc, char* argv[]) { // argv[0] is the path to binary file you're running // ... return 0; } 

利润是这种方法独立于平台,不需要任何系统调用。