Click here to Skip to main content
13,045,564 members (69,337 online)
Rate this:
Please Sign up or sign in to 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 !!

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 11:14am
Updated 3-Apr-13 12:05pm
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

Rate this: bad
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:[^].

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.


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 3 Apr 2013
Copyright © CodeProject, 1999-2017
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