CreateProcess() lpCurrentDirectory has no effect

CreateProcess() lpCurrentDirectory has no effect

本文关键字:no effect has lpCurrentDirectory CreateProcess      更新时间:2023-10-16

我想启动一个进程(exe文件),如果我将完整路径附加到我的命令行(lpCommandLine参数)一切都很好,但如果我将lpCurrentDirectory设置为[STARTDIR]系统说:

ERROR_FILE_NOT_FOUND

启动进程:

CreateProcessA(NULL,                    // No module name (use command line)
            &command[0],                        // Command line
            NULL,                               // Process handle not inheritable
            NULL,                               // Thread handle not inheritable
            FALSE,                              // Set handle inheritance to FALSE
            CREATE_NEW_CONSOLE,                 // No creation flags
            NULL,                               // Use parent's environment block
            [NULL] or [STARTDIR],               // Use parent's starting directory 
            startupInfo,                        // Pointer to STARTUPINFO structure
            processInfo)                        // Pointer to PROCESS_INFORMATION structure

->在这个文件夹中有一些其他的dll和我想要启动的exe

为什么这不起作用?

谢谢!

不行,不行。在启动过程中,新进程不会以该目录作为"当前"目录启动。相反,一旦进程启动,就会设置当前目录。

如果您希望您的进程在一个特定的目录中启动,那么您需要使用SetCurrentDirectory或其中一个或多或少可移植的变体(例如_chdir)。