Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MFC VC++
I want to call 3 .exe files on button clicked event
they have to be populate in sequence
after compliting first .exe file second will poped up.
after completing 2nd exe 3rd will be poped up.
 
if any of these 3 exe files doen't work it should populate message box (showing "error ")
 
How to do that? i have used ShellExecute()
 
Thank you !!
 
ShellExecute(NULL, ("open"),("1.exe"),NULL,NULL,SW_SHOWNORMAL);
ShellExecute(NULL, ("open"),("2.exe"),NULL,NULL,SW_SHOWNORMAL); 
ShellExecute(NULL, ("open"),("3.exe"),NULL,NULL,SW_SHOWNORMAL);
Posted 3-Apr-13 12:14pm
Edited 3-Apr-13 13:05pm
v2
Comments
joshrduncan2012 at 3-Apr-13 17:28pm
   
Where is your code that you have tried the shellexecute command?
peoria123 at 3-Apr-13 17:34pm
   
ShellExecute(NULL, ("open"),("1.exe"),NULL,NULL,SW_SHOWNORMAL);
 
ShellExecute(NULL, ("open"),("2.exe"),NULL,NULL,SW_SHOWNORMAL);
ShellExecute(NULL, ("open"),("3.exe"),NULL,NULL,SW_SHOWNORMAL);

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can do it, if you use the process handle returned by each ShellExecute; then you can use the function WaitForMultipleObjects:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms687025%28v=vs.85%29.aspx[^].
 
This function call will be a blocking call. Your calling thread would be set to wait state until all three processes are terminated. In this wait state, the calling thread will be switched off and not scheduled back to execution until waken up by some event, such as time out or when the condition (all processes are terminated) is satisfied. This way, the wait will spend zero CPU time, which is good.
 
As such call is blocking, as a rule of thumb, the calling thread should not be a UI thread. That said, if your application is a Windowed UI application, you will need to create a separate thread where you can do all the blocking calls. If you can reasonably expect that all three child processes can be completed in a very short period of time, you could do it even in a UI thread, but I wouldn't do it.
 
Moreover, I would avoid using ShellExecute and having any separate processes at all. It would be the best to turn them into DLL for in-proc use. You see, the processes are very well isolated; so you have a very limited access of control over a child process from your parent process. You can wait for its termination; if this is a simple console-only process, you can redirect its output to your process and handle it; and that's nearly all you can do. The different processes can effectively collaborate only if they are designed specially to do so, via some IPC mechanisms. I'm sure this is not your case, otherwise you would not ask this question.
 
—SA
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 609
1 OriginalGriff 587
2 Maciej Los 325
3 Mathew Soji 195
4 BillWoodruff 190
0 OriginalGriff 7,356
1 Sergey Alexandrovich Kryukov 6,712
2 DamithSL 5,461
3 Manas Bhardwaj 4,916
4 Maciej Los 4,475


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 3 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100