@echo off
setlocal

set "SCRIPT=%~dp0service.ps1"
if not exist "%SCRIPT%" (
    echo service.ps1 was not found next to this launcher.
    exit /b 1
)
set "NOWDNS_SERVICE_SCRIPT=%SCRIPT%"
set "NOWDNS_SERVICE_ACTION=%~1"

:: Keep the path in the environment so CMD does not interpolate it into PowerShell.
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "$ErrorActionPreference = 'Stop'; $script = $env:NOWDNS_SERVICE_SCRIPT; $quotedScript = [char]34 + $script + [char]34; $arguments = @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', $quotedScript); if ($env:NOWDNS_SERVICE_ACTION) { $arguments += @('-Action', $env:NOWDNS_SERVICE_ACTION) }; $process = Start-Process -FilePath 'powershell.exe' -Verb RunAs -WorkingDirectory (Split-Path -Parent $script) -ArgumentList $arguments -Wait -PassThru; exit $process.ExitCode"
exit /b %ERRORLEVEL%
