Updated version
The following will execute your setup program, then wait for there to be no more instances of setup.exe
running. There is a maximum timeout value you can set (so that it doesn't hang forever).
Please note that this can't detect whether setup is done, only whether or not a setup.exe
process is running. It's a minor distinction, but an important one.
Option Explicit
Const PROC_NAME = "setup.exe"
Const RUN_CMD = "setup.exe /qb /I Autocad2010.ini /language en-us"
Const SLEEP_INTERVAL_MS = 1000
Const WAIT_TIMEOUT_MS = 1500000 ' = 1000 * 60 * 25 ms = 25 mins
Dim objWshShell, objWMIService
Dim colProcesses, objProcess
Dim intWaited, blnProcessTerminated
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set objWshShell = WScript.CreateObject("WScript.Shell")
objWshShell.Run RUN_CMD
intWaited = 0
blnProcessTerminated = False
While intWaited < WAIT_TIMEOUT_MS And Not blnProcessTerminated
Set colProcesses = objWMIService.ExecQuery(_
"Select * from Win32_Process where Name='" & PROC_NAME & "'")
blnProcessTerminated = True
For Each objProcess In colProcesses
blnProcessTerminated = False
Next
WScript.Sleep(SLEEP_INTERVAL_MS)
intWaited = intWaited + SLEEP_INTERVAL_MS
Wend
This is relatively straightforward:
Option Explicit
Dim objWshShell
Set objWshShell = WScript.CreateObject("WScript.Shell")
objWshShell.Run "setup.exe /qb /I Autocad2010.ini /language en-us", 1, True
The parameters to the Run
method are described in greater detail on the MSDN site. Most importantly, True
causes the script to wait until setup.exe
has terminated.