@echo off
REM ===============================
REM DDNS Updater Install using NSSM
REM ===============================

REM Get the folder where this bat is located
SET SCRIPT_DIR=%~dp0

REM Define program and NSSM paths
SET EXE_NAME=DDNSUpdater.exe
SET EXE_PATH=%SCRIPT_DIR%%EXE_NAME%
SET NSSM_PATH=%SCRIPT_DIR%nssm.exe

REM Check if files exist
IF NOT EXIST "%EXE_PATH%" (
    echo ERROR: %EXE_NAME% not found in the same folder as this script.
    pause
    exit /b 1
)

IF NOT EXIST "%NSSM_PATH%" (
    echo ERROR: nssm.exe not found in the same folder as this script.
    pause
    exit /b 1
)

REM Remove existing service if present
"%NSSM_PATH%" remove DDNSUpdaterService confirm

REM Install service
"%NSSM_PATH%" install DDNSUpdaterService "%EXE_PATH%"

REM Optional: auto-start at boot
"%NSSM_PATH%" set DDNSUpdaterService Start SERVICE_AUTO_START

REM Start the service
"%NSSM_PATH%" start DDNSUpdaterService

echo.
echo DDNSUpdaterService installed and started successfully!
pause
