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 not exist %1 goto InvalidParam

if "%TEMP%"=="" goto NoTemp
pushd "%TEMP%"
if errorlevel 1 goto NoTempDir
popd

echo Installing %1...
goto %OFFICE_NAME%

:o2k
:oxp
:o2k3
for /F "tokens=3 delims=\." %%i in ("%1") do (
  %1 /T:"%TEMP%\%%i" /C /Q
  if errorlevel 1 (
    rd /S /Q "%TEMP%\%%i"
    goto InstError
  )
  if exist "%TEMP%\%%i\ohotfix.exe" (
    for /F "usebackq eol=; tokens=1,2 delims==" %%j in ("%TEMP%\%%i\ohotfix.ini") do (
      if /i "%%j"=="ShowSuccessDialog" echo %%j=0 >> "%TEMP%\%%i\ohotfix.1"
      if /i "%%j"=="UpgradeMsi" echo %%j=0 >> "%TEMP%\%%i\ohotfix.1"
      if /i "%%j"=="OHotfixUILevel" echo %%j=q >> "%TEMP%\%%i\ohotfix.1"
      if /i "%%j"=="MsiUILevel" echo %%j=n >> "%TEMP%\%%i\ohotfix.1"
      if exist "%TEMP%\%%i\ohotfix.1" (
        for /F "usebackq" %%l in ("%TEMP%\%%i\ohotfix.1") do (
          echo %%l >> "%TEMP%\%%i\ohotfix.new"
        )
        del "%TEMP%\%%i\ohotfix.1"
      ) else (
        echo %%j=%%k >> "%TEMP%\%%i\ohotfix.new"
      )
    )
    del "%TEMP%\%%i\ohotfix.ini"
    ren "%TEMP%\%%i\ohotfix.new" ohotfix.ini
    "%TEMP%\%%i\ohotfix.exe"
  ) else (
    if not exist "%TEMP%\%%i\setup.exe" (
      rd /S /Q "%TEMP%\%%i"
      goto InstError
    )
    "%TEMP%\%%i\setup.exe" /QB
  )
  rd /S /Q "%TEMP%\%%i"
)
echo %DATE% %TIME% - Info: Installed %1 >> %WSUS_LOGFILE%
goto EoF

:o2k7
%1 /quiet /norestart
echo %DATE% %TIME% - Info: Installed %1 >> %WSUS_LOGFILE%
goto EoF


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

:NoParam
echo ERROR: Invalid parameter. Usage: %~n0 filename
echo %DATE% %TIME% - Error: Invalid parameter. Usage: %~n0 filename >> %WSUS_LOGFILE%
goto Error

:InvalidParam
echo ERROR: File %1 not found.
echo %DATE% %TIME% - Error: File %1 not found >> %WSUS_LOGFILE%
goto Error

:NoTemp
echo ERROR: Environment variable TEMP not set.
echo %DATE% %TIME% - Error: Environment variable TEMP not set >> %WSUS_LOGFILE%
goto Error

:NoTempDir
echo ERROR: Directory "%TEMP%" not found.
echo %DATE% %TIME% - Error: Directory "%TEMP%" not found >> %WSUS_LOGFILE%
goto Error

: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
