{"record":{"id":"be533764b613752b","repo":"chenhg5/cc-connect","slug":"delete-scheduled-task-s-w","errorCode":null,"errorMessage":"delete scheduled task: %s (%w)","messagePattern":"delete scheduled task: (.+?) \\(%w\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"daemon/windows.go","lineNumber":267,"sourceCode":"\tout, err := runPowerShell(fmt.Sprintf(`\n$task = Get-ScheduledTask -TaskName %s -ErrorAction SilentlyContinue\nif ($null -eq $task) { Write-Error 'scheduled task not found'; exit 1 }\nif ($task.State -ne 'Running') { Start-ScheduledTask -TaskName %s }\n`, powerShellLiteral(windowsTaskName), powerShellLiteral(windowsTaskName)))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"start scheduled task: %s (%w)\", out, err)\n\t}\n\treturn nil\n}\n\nfunc deleteWindowsTask() error {\n\tout, err := runPowerShell(fmt.Sprintf(`\n$task = Get-ScheduledTask -TaskName %s -ErrorAction SilentlyContinue\nif ($null -eq $task) { exit 0 }\nUnregister-ScheduledTask -TaskName %s -Confirm:$false\n`, powerShellLiteral(windowsTaskName), powerShellLiteral(windowsTaskName)))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"delete scheduled task: %s (%w)\", out, err)\n\t}\n\treturn nil\n}\n\n// CheckLinger is a no-op on Windows (always returns false).\nfunc CheckLinger() (enabled bool, user string) {\n\treturn false, \"\"\n}\n","sourceCodeStart":249,"sourceCodeEnd":276,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/daemon/windows.go#L249-L276","documentation":"deleteWindowsTask wraps an error from runPowerShell running its Unregister-ScheduledTask script. The script exits 0 silently if the task does not exist, so this error means Unregister-ScheduledTask actually failed (or the PowerShell exec itself failed).","triggerScenarios":"Called by Install (when trying to remove a stale task before recreating it) and Uninstall on Windows, when Unregister-ScheduledTask -Confirm:$false returns an error: access denied, task owned by another user, task currently running/locked, or powershell.exe exec failure.","commonSituations":"Uninstalling a task created by another Windows account; insufficient privileges (task registered with elevated RunLevel); the task is running and locked; enterprise policy forbids task deletion.","solutions":["Read the %s output in the error for the exact Unregister-ScheduledTask failure.","Delete the task manually: `Unregister-ScheduledTask -TaskName <name> -Confirm:$false` in an elevated PowerShell.","Stop the task first (`Stop-ScheduledTask`) if it is running and locked.","Run the uninstall as the user who owns the task, or with elevation."],"exampleFix":"// manual cleanup when Unregister fails\nStop-ScheduledTask -TaskName cc-connect -ErrorAction SilentlyContinue\nUnregister-ScheduledTask -TaskName cc-connect -Confirm:$false","handlingStrategy":"try-catch","validationCode":"out, _ := exec.Command(\"powershell\", \"-NoProfile\", \"-Command\",\n\t\"(Get-ScheduledTask -TaskName '<name>').State\").Output()\nif strings.TrimSpace(string(out)) == \"Running\" {\n\texec.Command(\"powershell\", \"-NoProfile\", \"-Command\",\n\t\t\"Stop-ScheduledTask -TaskName '<name>'\").Run() // stop before uninstall\n}","typeGuard":null,"tryCatchPattern":"if err := daemon.Uninstall(); err != nil {\n\tif strings.Contains(err.Error(), \"delete scheduled task\") {\n\t\tslog.Warn(\"task deletion denied; try elevated PowerShell: Unregister-ScheduledTask -TaskName <name> -Confirm:$false\", \"error\", err)\n\t}\n}","preventionTips":["Stop the task before deleting it so it is not locked.","Uninstall under the account that registered the task, or elevate.","Check enterprise policy does not block task deletion."],"tags":["windows","scheduled-task","powershell","cleanup"],"backgroundTag":"permission-denied","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}