Fix Windows autostart task command

This commit is contained in:
2026-08-07 18:33:40 +08:00
parent 89463e2706
commit eeab017927
2 changed files with 28 additions and 2 deletions
+19
View File
@@ -0,0 +1,19 @@
@echo off
setlocal
cd /d "%~dp0"
set "LOG_DIR=%~dp0logs"
set "LOG_FILE=%LOG_DIR%\autostart.log"
if not exist "%LOG_DIR%" mkdir "%LOG_DIR%"
echo.>> "%LOG_FILE%"
echo [%DATE% %TIME%] Starting DocuTranslate autostart runner...>> "%LOG_FILE%"
call "%~dp0run.bat" >> "%LOG_FILE%" 2>&1
set "EXIT_CODE=%ERRORLEVEL%"
echo [%DATE% %TIME%] DocuTranslate stopped with exit code %EXIT_CODE%.>> "%LOG_FILE%"
exit /b %EXIT_CODE%
+9 -2
View File
@@ -6,6 +6,7 @@ cd /d "%~dp0"
set "TASK_NAME=DocuTranslate"
set "PROJECT_DIR=%~dp0"
set "RUN_BAT=%PROJECT_DIR%run.bat"
set "RUNNER_BAT=%PROJECT_DIR%autostart_runner.bat"
set "LOG_DIR=%PROJECT_DIR%logs"
set "LOG_FILE=%LOG_DIR%\autostart.log"
@@ -15,6 +16,12 @@ if not exist "%RUN_BAT%" (
exit /b 1
)
if not exist "%RUNNER_BAT%" (
echo [ERROR] Cannot find "%RUNNER_BAT%".
pause
exit /b 1
)
if not exist "%LOG_DIR%" mkdir "%LOG_DIR%"
REM Create a startup task. Run this file as Administrator.
@@ -24,7 +31,7 @@ schtasks /Create ^
/SC ONSTART ^
/RU SYSTEM ^
/RL HIGHEST ^
/TR "cmd.exe /c cd /d ""%PROJECT_DIR%"" && ""%RUN_BAT%"" >> ""%LOG_FILE%"" 2>&1" ^
/TR "\"%RUNNER_BAT%\"" ^
/F
if not "%ERRORLEVEL%"=="0" (
@@ -36,7 +43,7 @@ if not "%ERRORLEVEL%"=="0" (
echo.
echo [OK] Scheduled task "%TASK_NAME%" has been created.
echo [OK] It will run "%RUN_BAT%" at system startup.
echo [OK] It will run "%RUNNER_BAT%" at system startup.
echo [OK] Log file: "%LOG_FILE%"
echo.
echo You can start it now with: