@echo off
REM Remove nginx Windows Service
setlocal
set "NGINX_DIR=%~dp0"

net session >nul 2>&1
if %ERRORLEVEL% NEQ 0 (
    echo ERROR: This script requires administrator privileges.
    pause
    exit /b 1
)

if exist "%NGINX_DIR%nssm.exe" (
    set "NSSM=%NGINX_DIR%nssm.exe"
) else (
    set "NSSM=nssm"
)

echo Stopping service...
"%NSSM%" stop nginx 2>nul

echo Killing any remaining nginx processes...
taskkill /F /IM nginx.exe >nul 2>&1

echo Removing service...
"%NSSM%" remove nginx confirm
echo.
echo Service removed.
endlocal
