CreateProcess fails under windows 7

天大地大妈咪最大 提交于 2019-12-21 12:30:06

问题


I'm trying to compile legacy code from Windows XP under a new environment in Windows 7. It compiles but fails at runtime.

CreateProcess() returns 0 and GetLastError() returns 2, which stands for ERROR_FILE_NOT_FOUND

Here is my call to 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.

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.

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


回答1:


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.

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.



来源:https://stackoverflow.com/questions/7003981/createprocess-fails-under-windows-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!