Recently I was presented with an issue, and it was deploying multiple applications via sccm in a sequence, however the client did not want to make use of task sequences, and wanted the install to check for pre-existing applications and install if any were missing and that any errors during the install to be sent back to SCCM.

The Batch Script

@ECHO OFF
set regpath=HKLM\<Registry Path>
set regvalue=<Key>
set regdata= <Value>
reg query %regpath% /v %regvalue% | find /i %regdata%
if not error level 1 go to end
:not_found
echo Please wait while <Application name> is installed
<app install command line>
if not %errorlevel%"=="0" exit /30066
:end

if the install fails it will exit the batch file error code 30066

Examples

Microsoft .Net Framework 2.0

@ECHO OFF
set regpath=HKLM\SOFTWARE\MICROSOFT\NET FRAMEWORK SETUP\NDP\V2.0.5727
set regvalue=install
set regdata=1
reg query %regpath% /v %regvalue% | find /i %regdata%
if not error level 1 go to end
:not_found
echo Please wait while .net 2.0 is installed
dotnetfx.exe /q:a /c:"install /I /Q"
if not %errorlevel%"=="0" exit /30066
:end