rem *** Author: T. Wittrock, RZ Uni Kiel ***

verify other 2>nul
setlocal enableextensions
if errorlevel 1 goto NoExtensions

if "%WSUS_LOGFILE%"=="" set WSUS_LOGFILE=%SystemRoot%\ctupdate.log

if "%1"=="" goto NoParam

if /i "%2"=="/noretry" (
  set NORETRY=1
  shift /2
)
if /i "%2"=="/exitonerror" (
  set EXITONERROR=1
  shift /2
)

echo Installing %1...
if "%NORETRY%"=="1" (%1 %2 %3 %4 %5 %6 %7 %8 %9) else (RetryingUpdateInstaller.exe %1 %2 %3 %4 %5 %6 %7 %8 %9)
for %%i in (0 1641 3010 3011) do if %errorlevel% EQU %%i goto InstSuccess
if "%EXITONERROR%"=="1" (goto InstError) else (goto InstWarning) 

:NoExtensions
echo ERROR: No command extensions available.
goto Error

:NoParam
echo ERROR: Invalid parameter. Usage: %~n0 filename [/noretry] [/exitonerror] [switches]
echo %DATE% %TIME% - Error: Invalid parameter. Usage: %~n0 filename [/noretry] [/exitonerror] [switches] >> %WSUS_LOGFILE%
goto Error

:InstSuccess
echo %DATE% %TIME% - Info: Installed %1 >> %WSUS_LOGFILE%
goto EoF

:InstWarning
echo Warning: Installation of %1 failed (errorlevel: %errorlevel%)!
echo %DATE% %TIME% - Warning: Installation of %1 failed (errorlevel: %errorlevel%) >> %WSUS_LOGFILE%
goto EoF

:InstError
echo ERROR: Installation of %1 failed (errorlevel: %errorlevel%)!
echo %DATE% %TIME% - Error: Installation of %1 failed (errorlevel: %errorlevel%) >> %WSUS_LOGFILE%
goto Error

:Error
endlocal
exit /b 1

:EoF
endlocal
exit /b 0
