@echo off
::: suppress interaction  (Ex: batchfile.cmd -quiet)
set quiet=false
IF /I "%1" EQU "-quiet" set quiet=true
::: suppress interaction

set SRCH_PATH="%~dp0redemption*.dll"
echo --------------------------------------------------
echo - %~nx0
echo -
echo - This registers the redemption dlls required for Outlook
echo -
echo - Files to register: %SRCH_PATH%
echo --------------------------------------------------

:: ----------------------- START: Display files
echo -------- List of files to be registered -----------
SETLOCAL ENABLEDELAYEDEXPANSION
set c=0
for %%i in (%SRCH_PATH%) do (
	set fil=%%~i
	set /a c=!c!+1
	@echo !c!: !fil!
	)
echo -------- %c% files found -----------
:: ----------------------- END: Display files
if "%c%"=="0" GOTO :ERR4
:: --- pause
if /I "%quiet%" EQU "false" (pause) else (echo [-quiet: 5 seconds...] & ping -n 6 127.0.0.1>nul)
:: ----------------------- START: Loop through files
echo -------- Registering files  -----------
SETLOCAL ENABLEDELAYEDEXPANSION
set c=0
for %%i in (%SRCH_PATH%) do (
	set fil=%%~i
	set /a c=!c!+1
	@echo !c!: !fil!
	CALL :FIL
	)
:: ----------------------- END: Loop through files
GOTO :DONESCAN

:: ----------------------- START: Check one file up to scanmax times
:FIL
if /I "%quiet%" EQU "true" GOTO :FILQUIET
:FILNORMAL
c:\Windows\SysWOW64\regsvr32.exe "!fil!"
GOTO :FILDONE
:FILQUIET
c:\Windows\SysWOW64\regsvr32.exe "!fil!" /s
GOTO :FILDONE
:FILDONE
exit /b
:: ----------------------- END: Check one file up to scanmax times

:DONESCAN
GOTO :DONE

:ERR2
echo Err. %SRCH_PATH% can't be a UNC path.
GOTO :DONE

:ERR3
GOTO :DONE

:ERR4
echo No files found
pause
GOTO :DONE


:DONE
echo --------------------------------------------------
echo Done.
if /I "%quiet%" EQU "false" (pause) else (echo [-quiet: 5 seconds...] & ping -n 6 127.0.0.1>nul)
EXIT /b 0
