Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to create a script to execute an exe on shutdown in order to install sp1. my script goes something like (not actual bat script).

If installed GOTO END

My problem is that when it runs, it starts the installer, then finishes the script because the installer's a different process and follows up by shutting down the install process because the computer's shutting down and shutting down the system (at least, that's what i think it's doing.)

Is there any way to tell it to wait until the process it started completes and then shutdown?

share|improve this question
up vote 51 down vote accepted

Try running

START /WAIT Install.exe
share|improve this answer
great job with this answer! – l--''''''---------'''''''''''' Oct 17 '12 at 20:33
Can you chain? like start /wait install; exit? – Serj Sagan Jul 11 at 22:03

Either calling the exe directly from the batch file, or using start /wait will work but there is a caveat.

If the exe you call then creates other process, such as calling another exe, and then exits the batch file will continue processing after the called exe has terminated, as it has no knowledge of other processes started by it.

In your case this is a real problem because installers normally extract files from some form of compressed container, which may be embedded in the exe itself, then fire off one of the extracted files and exit. Some installers provide command line parameters which tell the original exe not to exit until the entire installation is complete, so that's something you may want to investigate. Other than that, there's no real way around this with batch files alone and would take a programmatic solution to solve.

share|improve this answer
You could always add a loop to the shutdown routine to check to see if msiexec.exe (or whatever the hell it is) is running and then wait and loop again. – mfinni Mar 9 '11 at 22:02
@mfinni, just to complicate matters even further, msiexec often fires off other processes as well. :( – John Gardeniers Mar 10 '11 at 1:31
Actually, why do you need start /wait at all? I myself believed it's needed to use start /wait to block batch file until GUI (as opposite to a console) application finishes. But testing it now, I see that batch files actually wait even for GUI applications. I have posted corresponding question: Why GUI application blocks a batch file? – Martin Prikryl Oct 15 '13 at 18:28

Here is an example using MATLAB! I have assumed that the path setup for MATLAB is done and MATLAB exit is being ensured by the FileName.m file (or user has specified it internally).

echo off
matlab -nosplash /r "FileName.m"
tasklist /fi "imagename eq MATLAB.exe" |find ":" > nul
if errorlevel 1 goto loop
share|improve this answer
Assuming Matlab seems a bit strange to me, especially here on serverfault. – Erik Jun 19 '14 at 12:55
This can work for things other than MATLAB. Just change "MATLAB.exe" to something else. And perhaps fix that second 'find' to search for the exe again in the filtered output. – Oliver Bock Jul 18 '14 at 6:17

One shorter way:




could be used , though with more eventually you'll be able to catch some console output. And this is the reason it works - the piped command waits for input until the .exe is finished

share|improve this answer
and why is the downlvote? – npocmaka Oct 22 '15 at 13:54
This is excellent! I up vote you. – Changwang Zhang Nov 25 '15 at 14:07

You can use the the start /wait command. This starts an application and waits for it to end.

Or if you know how long it takes to execute, you can take a look at the sleep command, provided by the Windows Server 2003 Resource Kit Tools . Sleep.exe can be used to pause your batch for any number of seconds to allow the program to install fully before the batch file proceeds to install anything else. There are some programs which ignore the "start /wait" syntax, due to the program itself launching another process, then the sleep.exe is very useful.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.