Use PowerShell for autostart task setup

This commit is contained in:
Leon committed 2026-08-07 18:34:58 +08:00
1 parent eeab017927
commit 5c4745537f
1 file changed
+6 -7
+6 -7
View File
@@ -26,13 +26,12 @@ if not exist "%LOG_DIR%" mkdir "%LOG_DIR%"
REM Create a startup task. Run this file as Administrator. 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. REM The task runs as SYSTEM, so it can start after reboot before desktop login.
schtasks /Create ^ powershell -NoProfile -ExecutionPolicy Bypass -Command ^
/TN "%TASK_NAME%" ^ "$Action = New-ScheduledTaskAction -Execute 'cmd.exe' -Argument '/c ""%RUNNER_BAT%""';" ^
/SC ONSTART ^ "$Trigger = New-ScheduledTaskTrigger -AtStartup;" ^
/RU SYSTEM ^ "$Principal = New-ScheduledTaskPrincipal -UserId 'SYSTEM' -RunLevel Highest;" ^
/RL HIGHEST ^ "$Settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -MultipleInstances IgnoreNew;" ^
/TR "\"%RUNNER_BAT%\"" ^ "Register-ScheduledTask -TaskName '%TASK_NAME%' -Action $Action -Trigger $Trigger -Principal $Principal -Settings $Settings -Force | Out-Null"
/F
if not "%ERRORLEVEL%"=="0" ( if not "%ERRORLEVEL%"=="0" (
echo. echo.