[batch] wait for process to finish

Discussion in 'Scripting' started by thethingy, Nov 29, 2011.

  1. thethingy

    thethingy MDL Senior Member

    Sep 7, 2010
    301
    40
    10
    how do I make a batch that checks for a process (msiexec.exe *32 [windows installer]) then waits for the process to finish then close?
     
  2. thethingy

    thethingy MDL Senior Member

    Sep 7, 2010
    301
    40
    10
    #2 thethingy, Nov 30, 2011
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Code:
    @echo off
    :Checking Installer Status
    ping -n 10 localhost >nul
    NET START | FIND "msiexec.exe" > nul
    IF %errorlevel1% == 1 (
    goto Retry
    ) else (
    goto exit
    
    :Retry
    ping -n 10 localhost >nul
    goto Checking Installer Status
    
    :exit
    CD ..
    START CMD /C RMDIR /S /Q "%~dp0"
    exit
    
    I can find the process and make the batch go back in case there was a delay in launching the installer service but on the "exit" menu I still dont know how to make the batch wait for the installer service to finish before cleaning up the setup files, anyone?
     
  3. fisherman

    fisherman MDL Novice

    May 5, 2008
    32
    0
    0
    Here is an example that launches the windows calculator program, and hangs around until the calc program is closed. Then it posts a message. It is a Visual Basic script, rather than a .cmd file

    You should be able to adapt it to your needs using vbs.

    Regards,
    jj

    ------Paste the following lines into a file named calc.vbs.
    ' Visial Basic Script
    ' --------------------------------------------
    ' -- HTTP Reference:
    ' -- http://msdn.microsoft.com/en-us/library/2f38xsxe(v=VS.85).aspx
    ' -- Date:
    ' -- Purpose: WshScriptExec Object
    ' -- The WshScriptExec object
    ' -- is returned by the Exec method of the WshShell object.
    ' -- The Exec method returns the WshScriptExec object either
    ' -- once the script or program has finished executing, or
    ' -- before the script or program begins executing.
    ' --------------------------------------------

    Dim WshShell, oExec
    '---------------------------------------------
    '--> The The The
    '--> Object Method Program Name
    Set WshShell = CreateObject("WScript.Shell")
    '---------------------------------------------
    Set myprogram = WshShell.Exec("calc")
    ' myprogram.status is a WScript.Shell Property
    ' that is set to =0 while calc is running.
    ' When calc is finished, the status becomes 1
    ' and the sleep loop is finished.
    '---------------------------------------------

    Do While myprogram.Status = 0
    WScript.Sleep 100
    Loop
    'When the program ends, do this.
    WScript.Echo "The Status Property is now: " & myprogram.Status