@echo off
set Status=unknown
setlocal EnableDelayedExpansion
:menu
:: MENU ================================
setlocal EnableDelayedExpansion
cls
echo.
echo   ----------------------------------------
call :test_service zapret
::echo   ZAPRET ON/OFF MANAGER Status: !Status!
echo   ----------------------------------------
echo.
echo   :: SERVICE
echo      1. ON  Service
echo      2. OFF Service
echo.
echo   ----------------------------------------
echo      0. Exit
echo.

set /p menu_choice=   Select option (0-2): 

if "%menu_choice%"=="1" goto service_on
if "%menu_choice%"=="2" goto service_off
if "%menu_choice%"=="0" exit /b

goto menu

:: TEST ==============================
:test_service
set "ServiceName=%~1"
set "ServiceStatus="
for /f "tokens=3 delims=: " %%A in ('sc query "%ServiceName%" ^| findstr /i "STATE"') do set "ServiceStatus=%%A"
set "ServiceStatus=%ServiceStatus: =%"
if "%ServiceStatus%"=="RUNNING" (
	call :PrintGreen "    ZAPRET ON/OFF MANAGER Status: RUNNING"
) else if "%ServiceStatus%"=="STOPPED" (
	call :PrintRed "    ZAPRET ON/OFF MANAGER Status: STOPPED"
) else (
	set ServiceStatus=Unknown
	call :PrintYellow "    ZAPRET ON/OFF MANAGER Status: Unknown"
)
set Status=%ServiceStatus%
exit /b

:: OFF ==============================
:service_off
cls
chcp 65001 > nul
set SRVCNAME=zapret
sc query "!SRVCNAME!" >nul 2>&1
if !errorlevel!==0 (
    net stop %SRVCNAME%
) else (
    echo Service "%SRVCNAME%" is not installed.
)
::pause
goto menu

sc start %SRVCNAME%

:: ON ==============================
:service_on
cls
chcp 65001 > nul
set SRVCNAME=zapret
sc query "!SRVCNAME!" >nul 2>&1
if !errorlevel!==0 (
    net start %SRVCNAME%
) else (
    echo Service "%SRVCNAME%" is not installed.
)
::pause
goto menu



:: Utility functions

:PrintGreen
powershell -NoProfile -Command "Write-Host \"%~1\" -ForegroundColor Green"
exit /b

:PrintRed
powershell -NoProfile -Command "Write-Host \"%~1\" -ForegroundColor Red"
exit /b

:PrintYellow
powershell -NoProfile -Command "Write-Host \"%~1\" -ForegroundColor Yellow"
exit /b