@echo off
setlocal
set "INSTALLER=%TEMP%\eie_outlook_installer_%RANDOM%_%RANDOM%.ps1"

echo A instalar o auxiliar do Outlook EIE...
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Invoke-WebRequest -UseBasicParsing -Uri 'https://encomendas.reboucasviana.pt/downloads/instalar_auxiliar_outlook.ps1' -OutFile '%INSTALLER%'"
if errorlevel 1 goto failure

powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%INSTALLER%"
set "RESULT=%ERRORLEVEL%"
del /q "%INSTALLER%" >nul 2>&1
if not "%RESULT%"=="0" goto failure

echo.
echo Auxiliar instalado. Volte a aplicacao e tente abrir o email novamente.
pause
exit /b 0

:failure
echo.
echo Nao foi possivel instalar o auxiliar do Outlook.
echo Confirme a ligacao a Internet e tente novamente.
pause
exit /b 1
