Click here to Skip to main content
15,888,401 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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 !!

C++
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
Updated 3-Apr-13 12:05pm
v2
Comments
joshrduncan2012 3-Apr-13 17:28pm    
Where is your code that you have tried the shellexecute command?
peoria123 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

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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900