@echo off

set SERVICE_NAME=AuthAgentService
set SERVICE_PATH=%~dp0AuthAgentService.exe

REM 检查服务是否存在
sc query %SERVICE_NAME% >nul 2>nul
if %errorlevel% equ 1060 (
    REM 服务不存在，注册服务
    sc create %SERVICE_NAME% binPath= "%SERVICE_PATH%" start= auto
    echo 服务已注册
)

REM 检查服务是否在运行
sc query %SERVICE_NAME% | find "STATE" | find "RUNNING" >nul
if %errorlevel% equ 0 (
    echo 服务已启动
) else (
    REM 启动服务
    net start %SERVICE_NAME%
    echo 服务已启动
)