CreateProcess 在 Windows 7 下失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7003981/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CreateProcess fails under windows 7
提问by Eric
I'm trying to compile legacy code from Windows XP under a new environment in Windows 7. It compiles but fails at runtime.
我正在尝试在 Windows 7 的新环境下从 Windows XP 编译遗留代码。它编译但在运行时失败。
CreateProcess() returns 0 and GetLastError() returns 2, which stands for ERROR_FILE_NOT_FOUND
CreateProcess() 返回 0,GetLastError() 返回 2,代表 ERROR_FILE_NOT_FOUND
Here is my call to CreateProcess
这是我对 CreateProcess 的调用
STARTUPINFO StartInfo;
memset(&StartInfo, 0, sizeof(StartInfo));
wcsncpy(astrCommandLine, L"TFTP", MAX_OSCOMMANDLINE_SZ-1);
BOOL bFuncRetn = CreateProcess(NULL,
astrCommandLine, // command line
NULL, // process security attributes
NULL, // primary thread security attributes
NULL, // handles are inherited
0, // creation flags
NULL, // use parent's environment
NULL, // use parent's current directory
&StartInfo, // STARTUPINFO pointer
&m_ProcInfo ); // receives PROCESS_INFORMATION
Now for the oddities : When instead of tftp I run calc, calc pops up. I can execute whatever is on my command line from anywhere in a command prompt so it tells me that the %PATH% to c:\windows\system32 is known and works correctly.
现在奇怪:当我运行 calc 而不是 tftp 时,calc 会弹出。我可以从命令提示符的任何位置执行命令行上的任何内容,因此它告诉我 %PATH% 到 c:\windows\system32 是已知的并且可以正常工作。
I tried to force CreateProcessA with ansi strings but I got the same result. I also tried in debug and release configuration and from command line.
我试图用 ansi 字符串强制 CreateProcessA 但我得到了相同的结果。我还尝试了调试和发布配置以及命令行。
Any idea?
任何的想法?
EDIT :
both calc.exe and tftp.exe are located in c:\windows\system32 which is in the system path.
running "c:\windows\system32\tftp" does not work
编辑: calc.exe 和 tftp.exe 都位于系统路径中的 c:\windows\system32 中。
运行“c:\windows\system32\tftp”不起作用
回答by Michael Vuozzo
The problem is that you have a 32 bit application trying to execute a 64 bit Windows command. You do not have to recompile your application as 64 bit to solve the problem. All you have to do is change all occurrences of c:\windows\system32 to c:\windows\SysNative.
问题是您有一个 32 位应用程序试图执行 64 位 Windows 命令。您不必将应用程序重新编译为 64 位来解决问题。您所要做的就是将所有出现的 c:\windows\system32 更改为 c:\windows\SysNative。
In Windows 7 x64, references to c:\windows\system32 from 32 bit programs are automatically redirected to c:\windows\syswow64. Using the special alias c:\windows\SysNative causes Windows 7 to not do the redirect.
在 Windows 7 x64 中,32 位程序对 c:\windows\system32 的引用会自动重定向到 c:\windows\syswow64。使用特殊别名 c:\windows\SysNative 会导致 Windows 7 不执行重定向。