[英]CreateProcess fails under windows 7
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.现在奇怪的是:当我运行 calc 而不是 tftp 时,会弹出 calc。 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.
我可以从命令提示符的任何位置执行我的命令行上的任何内容,因此它告诉我 c:\windows\system32 的 %PATH% 是已知的并且可以正常工作。
I tried to force CreateProcessA with ansi strings but I got the same result.我试图用 ansi 字符串强制 CreateProcessA,但我得到了相同的结果。 I also tried in debug and release configuration and from command line.
我还尝试了调试和发布配置以及命令行。
Any idea?任何想法?
EDIT: both calc.exe and tftp.exe are located in c:\windows\system32 which is in the system path.编辑: calc.exe 和 tftp.exe 都位于系统路径中的 c:\windows\system32 中。
running "c:\windows\system32\tftp" does not work运行“c:\windows\system32\tftp”不起作用
The problem is that you have a 32 bit application trying to execute a 64 bit Windows command.问题是您有一个 32 位应用程序试图执行 64 位 Windows 命令。 You do not have to recompile your application as 64 bit to solve the problem.
您不必将应用程序重新编译为 64 位即可解决问题。 All you have to do is change all occurrences of c:\windows\system32 to c:\windows\SysNative.
您所要做的就是将所有出现的 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.在 Windows 7 x64 中,对 c:\windows\system32 的引用从 32 位程序自动重定向到 Z4A8A08F09D37B73795649038408B5F343Z: Using the special alias c:\windows\SysNative causes Windows 7 to not do the redirect.
使用特殊别名 c:\windows\SysNative 会导致 Windows 7 不执行重定向。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.