0

I already found the code to make the programm wait for ShellExecuteEx in this thread. How can i make ShellExecuteEx start multiple files and wait until every file is closed?

Here is the code to wait for one:

SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "c:\\MyProgram.exe";        
ShExecInfo.lpParameters = "";   
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL; 
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
Community
  • 1
  • 1
drgy
  • 9
  • 2
  • Call `ShellExecuteEx` multiple times, once per file you want to start, then wait on all handles (either at once with `WaitForMultipleObjects`, or one by one). – Igor Tandetnik Jan 05 '15 at 22:21
  • I got this for the waitingpart : `WaitForMultipleObjects(4, hProcess, TRUE, INFINITE)` But how can I assign different HANDELS to each execution of the file ? – drgy Jan 06 '15 at 09:39
  • That wouldn't compile. The second parameter of `WaitForMultipleObjects` is not `HANDLE` but `HANDLE*` - a pointer to an array of `N` handles, where `N` is the first parameter. Anyway, to make things simple, you can just call `WaitForSingleObject` in a loop, once for each handle. – Igor Tandetnik Jan 06 '15 at 13:45

0 Answers0