Add Windows autostart setup

This commit is contained in:
2026-08-07 18:29:53 +08:00
parent 64c292db82
commit 89463e2706
2 changed files with 46 additions and 0 deletions
+1
View File
@@ -7,6 +7,7 @@ wheels/
*.egg-info
tests/resource/
docutranslate/output/
logs/
# Shared glossary runtime data
data/
# Virtual environments
+45
View File
@@ -0,0 +1,45 @@
@echo off
setlocal
cd /d "%~dp0"
set "TASK_NAME=DocuTranslate"
set "PROJECT_DIR=%~dp0"
set "RUN_BAT=%PROJECT_DIR%run.bat"
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 "%LOG_DIR%" mkdir "%LOG_DIR%"
REM Create a startup task. Run this file as Administrator.
REM The task runs as SYSTEM, so it can start after reboot before desktop login.
schtasks /Create ^
/TN "%TASK_NAME%" ^
/SC ONSTART ^
/RU SYSTEM ^
/RL HIGHEST ^
/TR "cmd.exe /c cd /d ""%PROJECT_DIR%"" && ""%RUN_BAT%"" >> ""%LOG_FILE%"" 2>&1" ^
/F
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] It will run "%RUN_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.
pause