Determine when process is completed

I have a batch file with syntax such this and I need to verify that all processes are complete. How can I adjust the syntax or otherwise verify success?
\\Location\Ccmsetup.exe SMSSITECODE=wtx SMSCACHESIZE=5120 SMSCONFIGSOURCE=U PATCH=\\Filepath.msp;Filepath.msp;\\Filepath.msp

Open in new window

frugalmuleAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NVITEnd-user supportCommented:
> ...verify that all processes are complete.
Are you saying when this is run, it does not continue on the next line until Ccmsetup.exe complete?
Or, does it continue to the next line and each .msp is running on its own process?

If the first, many .exe programs return an error code. You can check as follows:
\\Location\Ccmsetup.exe SMSSITECODE=wtx SMSCACHESIZE=5120 SMSCONFIGSOURCE=U PATCH=\\Filepath.msp;Filepath.msp;\\Filepath.msp
set result=%errorlevel%
echo %result%
pause

Open in new window

oBdACommented:
ccmsetup is a bit tricky, because the instance you start will launch a second instance under LocalSystem that will do the actual install, while the initial instance exits.
This should do the trick:
@echo off
setlocal enabledelayedexpansion
set CcmSetup=\\Location\Ccmsetup.exe
set CcmSetupArgs=SMSSITECODE=wtx SMSCACHESIZE=5120 SMSCONFIGSOURCE=U PATCH=\\Filepath.msp;Filepath.msp;\\Filepath.msp
set CcmSetupLog=%SystemRoot%\ccmsetup\Logs\client.msi.log
set TempFile=%Temp%\wmic.tmp
set Timeout=120
set DefaultErrorLevel=9999

REM *** The first instance of ccmsetup.exe will invoke a second instance started by local system, and exit.
REM *** The second instance will do the actual install.
for %%a in ("%CcmSetup%") do set CcmSetupProcess=%%~nxa
echo Starting '%CcmSetupProcess%' ...
wmic.exe process call create "%CcmSetup:"=\"% %CcmSetupArgs:"=\"%" >"%TempFile%"
set ProcessId=
set ReturnValue=
for /f "tokens=1,2 delims=;= " %%a in ('type "%TempFile%"') do (set %%a=%%b)
if not defined ProcessId (
	echo ERROR: Unable to start '%CcmSetup%' with arguments '%CcmSetupArgs%'.
	exit /b 1
)
echo ... initial process started with PID %ProcessId%.

<NUL set /p Dummy=Waiting for installation process to start .
set /a AttemptCount = 0
set InstallPid=
:WaitForInstallationBegin
for /f "tokens=2" %%a in ('tasklist.exe /FI "IMAGENAME eq %CcmSetupProcess%" ^| find.exe /i "%CcmSetupProcess%"') do (
	if not "%%a"=="%ProcessId%" set InstallPid=%%a
)
if not defined InstallPid (
	ping.exe -n 2 localhost >NUL
	<NUL set /p Dummy=.
	set /a AttemptCount += 1
	if !AttemptCount! gtr %Timeout% (
		echo.
		echo ERROR: Actual installation process did not start in the alloted time of %Timeout% seconds.
		exit /b %DefaultErrorLevel%
	)
	goto WaitForInstallationBegin
)
echo.
echo ... actual installation process started with PID %InstallPid% at %Date% %Time%.

<NUL set /p Dummy=Waiting for installation process to finish .
:WaitForInstallationEnd
set InstallPid=
for /f "tokens=2" %%a in ('tasklist.exe /FI "IMAGENAME eq %CcmSetupProcess%" ^| find.exe /i "%CcmSetupProcess%"') do (
	if not "%%a"=="%ProcessId%" set InstallPid=%%a
)
if defined InstallPid (
	ping.exe -n 2 localhost >NUL
	<NUL set /p Dummy=.
	goto WaitForInstallationEnd
)
echo.
echo ... actual installation process ended at %Date% %Time%.

echo Checking errorlevel in '%CcmSetupLog%' ...
set MsiErrorLevel=%DefaultErrorLevel%
for /f "tokens=8" %%a in ('type "%CcmSetupLog%" ^| find.exe /i "MainEngineThread is returning"') do set MsiErrorLevel=%%a
echo ... msiexec returned errorlevel %MsiErrorLevel%.
exit /b %MsiErrorLevel%

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Senior IT System EngineerIT ProfessionalCommented:
Does the batch script can be executed as part of the startup script ?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.