Need Help Changing WinExec() to CreateProcess()

Good morning everyone,

I am quite new to programming. I need to change the following to CreateProcess():

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdlib.h>
#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
    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);
    WinExec("cmd.exe /c for /F \"tokens=*\" %c in (\'dir /s /b %TEMP%\\*MyProgram.exe\') do (%SYSTEMDRIVE% & cd %~pc & start \"%c\")", SW_HIDE);
    return 0;
}


I need each command to wait for the previous command to complete/exit before executing. WinExec() cannot made made to wait and this is the main reason for requiring CreateProcess(). In line #2, program.exe is executed but it takes about 1 minute to complete. With WinExec(), this causes line #3 to fail.

Could someone help me to write this?

As always, I would greatly appreciate the help.

Thanks.
Topic archived. No new replies allowed.