You can try this as the parameters
CreateProcess(NULL, "C:\\Windows\\system32\\cmd.exe \C runBat.bat", NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
\c will enable to give parametes as a string.
Thanks
Ganesh
I believe you are getting the parameters wrong. The first parameter is just a name, the second is the command line, and the third holds the parameters to the process.
You almost got it right with your second attempt.
CreateProcess(NULL, "C:\\Windows\\system32\\cmd.exe", "runBat.bat", NULL, FALSE, 0, NULL, NULL, &si, &pi);
Should do the trick
//Magnus
/* The library I used is from Dev-C++ 4.9.9.2. I haven't try the VC's. The OS is Windows XP, SP2 */
The "Parameters lpApplicationName" section above says "To run a batch file, you must start the command interpreter; set lpApplicationName to cmd.exe and set lpCommandLine to the name of the batch file." But when I did so in a console program with:
CreateProcess("C:\\Windows\\system32\\cmd.exe", "runBat.bat", NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
or
CreateProcess(NULL, "C:\\Windows\\system32\\cmd.exe runBat.bat", NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
, the cmd.exe ignored the "runBat.bat" completely, i.e. the new cmd instance was booted smoothly while my "runBat.bat" wasn't executed. Furthermore, when I specified the cmd.exe without its complete path as:
CreateProcess("cmd.exe", "runBat.bat", NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
CreateProcess() return with FALSE, and GetLastError() return 2.
At last I found the followings work:
CreateProcess(NULL, "runBat.bat file1.txt file2.txt", NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
and
CreateProcess("runBat.bat ", "file1.txt file2.txt", NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
However, when I wanted to redirect the stdin and stdout of a called program in runBat.bat to the file1.txt and file2.txt respectively, only the former could work as expected. The latter caused such situation: file1.txt was opened with notepad and the cmd window was blocked until I closed the notepad manually. Furthermore, file2.txt had not be written in at all.
THERE SHOULD BE A WAY TO LAUNCH a process with the window as "ALWAYS ON TOP" USING THIS FUNCTION. This is not a robust enough function.
Note: This is not an appropriate forum for editorializing. A process that is not designed to be TOPMOST should not be created as TOPMOST. An application that is designed to be TOPMOST should be capable of making itself TOPMOST.