@echo off
setlocal EnableExtensions

title Windows Update - All

:: ============================================================
:: Update-All.bat
::
:: Starts Update-All.ps1.
::
:: The PowerShell script:
::   - Updates current-user applications
::   - Updates machine-wide applications using UAC
::   - Updates Microsoft Store applications
::   - Updates Microsoft Defender signatures
::   - Checks Windows Update services
::   - Does NOT automatically install hardware drivers
::   - Does NOT update GPU drivers
::   - Does NOT reboot Windows
::
:: ============================================================

set "SCRIPT=%~dp0Update-All.ps1"

if not exist "%SCRIPT%" (
    echo.
    echo ============================================================
    echo ERROR
    echo ============================================================
    echo.
    echo Update-All.ps1 was not found.
    echo.
    echo Expected:
    echo %SCRIPT%
    echo.
    pause
    exit /b 1
)

echo.
echo ============================================================
echo WINDOWS UPDATE - UPDATE EVERYTHING
echo ============================================================
echo.
echo Starting:
echo %SCRIPT%
echo.

:: Make sure PowerShell starts in the script directory.
pushd "%~dp0"

powershell.exe ^
    -NoProfile ^
    -ExecutionPolicy Bypass ^
    -File "%SCRIPT%"

set "EXITCODE=%ERRORLEVEL%"

popd

echo.
echo ============================================================
echo Update process finished.
echo ============================================================
echo.

if not "%EXITCODE%"=="0" (
    echo PowerShell returned exit code: %EXITCODE%
    echo.
)

echo Log is stored by the PowerShell script.
echo.

pause

endlocal
exit /b %EXITCODE%