fix: use Register-ScheduledTask -Force instead of delete-then-create to avoid losing tasks on failure
This commit is contained in:
@@ -563,9 +563,6 @@ function Setup-AutoStart {
|
|||||||
"@
|
"@
|
||||||
$hubScript | Set-Content $hubScriptPath -Encoding UTF8
|
$hubScript | Set-Content $hubScriptPath -Encoding UTF8
|
||||||
|
|
||||||
$oldHub = Get-ScheduledTask -TaskName "HAPI Hub" -ErrorAction SilentlyContinue
|
|
||||||
if ($oldHub) { Unregister-ScheduledTask -TaskName "HAPI Hub" -Confirm:$false }
|
|
||||||
|
|
||||||
$trigger = New-ScheduledTaskTrigger -AtLogon
|
$trigger = New-ScheduledTaskTrigger -AtLogon
|
||||||
$action = New-ScheduledTaskAction -Execute "powershell.exe" `
|
$action = New-ScheduledTaskAction -Execute "powershell.exe" `
|
||||||
-Argument "-WindowStyle Hidden -ExecutionPolicy Bypass -File `"$hubScriptPath`""
|
-Argument "-WindowStyle Hidden -ExecutionPolicy Bypass -File `"$hubScriptPath`""
|
||||||
@@ -577,9 +574,6 @@ function Setup-AutoStart {
|
|||||||
-Principal $principal -Settings $settings -Force | Out-Null
|
-Principal $principal -Settings $settings -Force | Out-Null
|
||||||
Write-Ok "HAPI Hub 计划任务已创建"
|
Write-Ok "HAPI Hub 计划任务已创建"
|
||||||
|
|
||||||
$oldRunner = Get-ScheduledTask -TaskName "HAPI Runner" -ErrorAction SilentlyContinue
|
|
||||||
if ($oldRunner) { Unregister-ScheduledTask -TaskName "HAPI Runner" -Confirm:$false }
|
|
||||||
|
|
||||||
$hapiHome = Join-Path $env:USERPROFILE ".hapi"
|
$hapiHome = Join-Path $env:USERPROFILE ".hapi"
|
||||||
New-Item -ItemType Directory -Force -Path $hapiHome | Out-Null
|
New-Item -ItemType Directory -Force -Path $hapiHome | Out-Null
|
||||||
$settingsJson = @"
|
$settingsJson = @"
|
||||||
|
|||||||
Reference in New Issue
Block a user