CreateProcess Error in Windows 7

I am trying to compile legacy code from Windows XP in a new environment in Windows 7. It compiles but does not execute at runtime.

CreateProcess () returns 0 and GetLastError () returns 2, which means 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 environment NULL, // use parent current directory &StartInfo, // STARTUPINFO pointer &m_ProcInfo ); // receives PROCESS_INFORMATION 

Now for the weird thing: when I run calc instead of tftp, a popup is called up. I can do everything on the command line from anywhere on the command line, so it tells me that% PATH% to c: \ windows \ system32 is known and working correctly.

I tried to force CreateProcessA with ansi strings, but I got the same result. I also tried in the debug and release configuration and from the command line.

Any idea?

EDIT: both files calc.exe and tftp.exe are located in the c: \ windows \ system32 directory, which is located in the system path.
running "c: \ windows \ system32 \ tftp" does not work.

+6
source share
1 answer

The problem is that you have a 32-bit application trying to execute a 64-bit Windows command. You do not need to recompile the application as 64 bits to solve the problem. All you have to do is change all occurrences of c: \ windows \ system32 to c: \ windows \ SysNative.

On Windows 7 x64, links 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 redirect.

+9
source

Source: https://habr.com/ru/post/894684/


All Articles