@echo off
title Siraya Printer - Stop Before Install
color 0E

>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (
    echo Click YES on admin prompt...
    goto UACPrompt
) else (
    goto gotAdmin
)

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\siraya_stopadmin.vbs"
    echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\siraya_stopadmin.vbs"
    "%temp%\siraya_stopadmin.vbs"
    exit /B

:gotAdmin
echo.
echo  Stopping Siraya printer agent (unlocks files for install)...
echo.
set "STOPPS1=%TEMP%\SirayaStop\stop-agent.ps1"
mkdir "%TEMP%\SirayaStop" 2>nul
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Invoke-WebRequest -UseBasicParsing -Uri 'https://pos.siraya.food/downloads/printer/tools/stop-agent.ps1' -OutFile '%STOPPS1%'"
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%STOPPS1%"
echo.
echo  Now run Install.cmd or Update.cmd from the printer folder.
echo.
pause
