@echo off setlocal cd /d "%~dp0" powershell -NoProfile -Command "if (([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { exit 0 } else { exit 1 }" >nul 2>&1 if not "%ERRORLEVEL%"=="0" ( set "DOCUTRANSLATE_SETUP_BAT=%~f0" echo [INFO] Administrator permission is required. Opening the UAC prompt... powershell -NoProfile -ExecutionPolicy Bypass -Command "Start-Process -FilePath $env:DOCUTRANSLATE_SETUP_BAT -Verb RunAs" exit /b ) set "TASK_NAME=DocuTranslate" set "WATCHDOG_TASK_NAME=DocuTranslateWatchdog" set "PROJECT_DIR=%~dp0" set "RUN_BAT=%PROJECT_DIR%run.bat" set "RUNNER_BAT=%PROJECT_DIR%autostart_runner.bat" set "WATCHDOG_BAT=%PROJECT_DIR%watchdog.bat" set "SETUP_PS1=%PROJECT_DIR%setup_autostart.ps1" set "LOG_DIR=%PROJECT_DIR%logs" set "LOG_FILE=%LOG_DIR%\autostart.log" if not exist "%RUN_BAT%" ( echo [ERROR] Cannot find "%RUN_BAT%". pause exit /b 1 ) if not exist "%RUNNER_BAT%" ( echo [ERROR] Cannot find "%RUNNER_BAT%". pause exit /b 1 ) if not exist "%WATCHDOG_BAT%" ( echo [ERROR] Cannot find "%WATCHDOG_BAT%". pause exit /b 1 ) if not exist "%SETUP_PS1%" ( echo [ERROR] Cannot find "%SETUP_PS1%". pause exit /b 1 ) powershell -NoProfile -ExecutionPolicy Bypass -File "%SETUP_PS1%" if not "%ERRORLEVEL%"=="0" ( echo. echo [ERROR] Failed to create scheduled task. Please run this file as Administrator. pause exit /b 1 ) echo. echo [OK] Scheduled task "%TASK_NAME%" has been created. echo [OK] Scheduled task "%WATCHDOG_TASK_NAME%" has been created. echo [OK] It will run "%RUNNER_BAT%" at system startup. echo [OK] Log file: "%LOG_FILE%" echo. echo You can start it now with: echo schtasks /Run /TN "%TASK_NAME%" echo. echo Double-click check_autostart.bat to verify tasks and HTTP health. echo Double-click diagnose_service.bat to collect restart and failure evidence. echo. pause