chenhg5/cc-connect · error
delete scheduled task: %s (%w)
Error message
delete scheduled task: %s (%w)
What it means
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).
Source
Thrown at daemon/windows.go:267
out, err := runPowerShell(fmt.Sprintf(`
$task = Get-ScheduledTask -TaskName %s -ErrorAction SilentlyContinue
if ($null -eq $task) { Write-Error 'scheduled task not found'; exit 1 }
if ($task.State -ne 'Running') { Start-ScheduledTask -TaskName %s }
`, powerShellLiteral(windowsTaskName), powerShellLiteral(windowsTaskName)))
if err != nil {
return fmt.Errorf("start scheduled task: %s (%w)", out, err)
}
return nil
}
func deleteWindowsTask() error {
out, err := runPowerShell(fmt.Sprintf(`
$task = Get-ScheduledTask -TaskName %s -ErrorAction SilentlyContinue
if ($null -eq $task) { exit 0 }
Unregister-ScheduledTask -TaskName %s -Confirm:$false
`, powerShellLiteral(windowsTaskName), powerShellLiteral(windowsTaskName)))
if err != nil {
return fmt.Errorf("delete scheduled task: %s (%w)", out, err)
}
return nil
}
// CheckLinger is a no-op on Windows (always returns false).
func CheckLinger() (enabled bool, user string) {
return false, ""
}
View on GitHub (pinned to 4000b2338a)
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.
Example fix
// manual cleanup when Unregister fails Stop-ScheduledTask -TaskName cc-connect -ErrorAction SilentlyContinue Unregister-ScheduledTask -TaskName cc-connect -Confirm:$false
Defensive patterns
Strategy: try-catch
Validate before calling
out, _ := exec.Command("powershell", "-NoProfile", "-Command",
"(Get-ScheduledTask -TaskName '<name>').State").Output()
if strings.TrimSpace(string(out)) == "Running" {
exec.Command("powershell", "-NoProfile", "-Command",
"Stop-ScheduledTask -TaskName '<name>'").Run() // stop before uninstall
} Try / catch
if err := daemon.Uninstall(); err != nil {
if strings.Contains(err.Error(), "delete scheduled task") {
slog.Warn("task deletion denied; try elevated PowerShell: Unregister-ScheduledTask -TaskName <name> -Confirm:$false", "error", err)
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Permission denied / not authorized / 403 Forbidden: access-control rejections when the caller lacks the required role, grant, or ownership — this error's family across 18 libraries.
Related errors
- register scheduled task: %s (%w)
- start scheduled task: %s (%w)
- powershell.exe not found: Windows Task Scheduler management
- start existing task: %w
- start task: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/be533764b613752b.
Report an issue: GitHub.