{"record":{"id":"29fe9c9fda1aee5f","repo":"chenhg5/cc-connect","slug":"start-scheduled-task-s-w","errorCode":null,"errorMessage":"start scheduled task: %s (%w)","messagePattern":"start scheduled task: (.+?) \\(%w\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"daemon/windows.go","lineNumber":255,"sourceCode":"\tStart-Sleep -Milliseconds 500\n}\nWrite-Error 'scheduled task did not stop within timeout'\nexit 1\n`, powerShellLiteral(windowsTaskName), powerShellLiteral(windowsTaskName), powerShellLiteral(windowsTaskName)))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"stop scheduled task: %s (%w)\", out, err)\n\t}\n\treturn nil\n}\n\nfunc startWindowsTask() error {\n\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) {","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/daemon/windows.go#L237-L273","documentation":"startWindowsTask wraps an error from runPowerShell running its start script. The script errors with 'scheduled task not found' if Get-ScheduledTask returns nothing, otherwise calls Start-ScheduledTask when the task is not already Running. The wrapped error means the task is missing or Start-ScheduledTask failed.","triggerScenarios":"Called by Start/Restart (and indirectly by Install) on Windows when: Get-ScheduledTask finds no task with windowsTaskName (Write-Error + exit 1), Start-ScheduledTask returns an error, or powershell.exe exec fails.","commonSituations":"Starting/restarting the daemon before it was ever installed; the task was deleted manually in Task Scheduler; different user session (task is per-user AtLogOn); corrupted task entry.","solutions":["Run `cc-connect daemon install` (or Install()) first — a 'scheduled task not found' error means no task exists.","Check the task exists for the current user: `Get-ScheduledTask -TaskName <name>`.","Read the wrapped output; if Start-ScheduledTask failed, verify the Task Scheduler service (`Get-Service Schedule`) is running.","Reinstall to recreate a fresh task if the entry is corrupt."],"exampleFix":"// before\ndaemon.Start()\n// after: guard with a status check\nif !daemon.Installed() {\n\tif err := daemon.Install(scriptPath); err != nil { /* handle */ }\n}\nif err := daemon.Start(); err != nil { /* handle */ }","handlingStrategy":"validation","validationCode":"if !daemon.Installed() {\n\tif err := daemon.Install(scriptPath); err != nil {\n\t\treturn err\n\t}\n}\n// safe to Start() now","typeGuard":null,"tryCatchPattern":"if err := daemon.Start(); err != nil {\n\tif strings.Contains(err.Error(), \"scheduled task not found\") {\n\t\tif instErr := daemon.Install(scriptPath); instErr != nil {\n\t\t\tslog.Error(\"auto-install failed\", \"error\", instErr)\n\t\t} else {\n\t\t\terr = daemon.Start()\n\t\t}\n\t}\n}","preventionTips":["Never Start before Install — always install first or guard with an Installed() check.","Do not delete the task manually in Task Scheduler; use the daemon's Uninstall.","Perform Start/Restart under the same Windows user that registered the task."],"tags":["windows","scheduled-task","powershell","process-start"],"backgroundTag":"resource-not-found","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"}