Why Won't This WinExec() Command Not Work?

Hello once again,

I am so confused and frustrated with this - I hope someone can help.

The following does not work:

WinExec("cmd.exe /c for /F \"tokens=*\" %c in (\'dir /s /b %TEMP%\\*MyProgram.exe\') do (%SYSTEMROOT% & cd %~pc & start \"%c\")", SW_HIDE);

But, the following 2 lines work just fine:

1
2
WinExec("cmd.exe /c for /F \"tokens=*\" %a in (\'dir /s /b PROGRAMS\') do (if not exist \"%TEMP\\PROGRAMS%~pa\" md \"%TEMP%\\PROGRAMS%~pa\")", SW_HIDE);
WinExec("cmd.exe /c for /F \"tokens=*\" %b in (\'dir /s /b PROGRAMS\') do (PROGRAMS\\program.exe \"%b\" \"%TEMP%\\PROGRAMS%~pnb\")", SW_HIDE);


What am I missing?
You should not use WinExec at all since
This function is provided only for compatibility with 16-bit Windows. Applications should use the CreateProcess function

https://msdn.microsoft.com/en-us/library/windows/desktop/ms687393(v=vs.85).aspx
If you really have to use it check the return value. It will tell you what's wrong.
I apologize for the late response. I wanted to say thank you for your answer.
Topic archived. No new replies allowed.