fix: 计划任务 Action 参数改单引号拼接(`\" 非 PowerShell 转义引号,导致新电脑注册任务时路径被当位置参数)

This commit is contained in:
luckyyzh
2026-08-03 18:56:24 +08:00
parent bd4eb05a2a
commit 75b8c83ea3
+3 -3
View File
@@ -40,9 +40,9 @@ function Ensure-Tasks {
if (-not (Get-ScheduledTask -TaskName $webTaskName -ErrorAction SilentlyContinue)) {
Write-Host " 注册计划任务 $webTaskName ..."
$supervisorPath = Join-Path $PSScriptRoot 'pi-agent-web-supervisor.ps1'
$action = New-ScheduledTaskAction -Execute 'powershell.exe' `
-Argument "-NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -WindowStyle Hidden -File `\"$supervisorPath`\"" `
-WorkingDirectory $projectRoot
# 单引号拼接避免转义歧义(`\" 不是 PowerShell 转义引号)
$argument = '-NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -WindowStyle Hidden -File "' + $supervisorPath + '"'
$action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument $argument -WorkingDirectory $projectRoot
$trigger = New-ScheduledTaskTrigger -AtLogOn
$settings = New-ScheduledTaskSettingsSet -StartWhenAvailable `
-RestartCount 999 -RestartInterval (New-TimeSpan -Minutes 1) `