chenhg5/cc-connect · error

register scheduled task: %s (%w)

Error message

register scheduled task: %s (%w)

What it means

createWindowsTask wraps an error from runPowerShell executing a Register-ScheduledTask script. The message includes the captured stdout/stderr (out) plus the wrapped error, indicating the scheduled task could not be registered with Task Scheduler. %s carries the PowerShell output, %w the exec error.

Source

Thrown at daemon/windows.go:158

}

func windowsTaskAction(scriptPath string) string {
	return fmt.Sprintf(`powershell.exe %s`, windowsTaskActionArgs(scriptPath))
}

func windowsTaskActionArgs(scriptPath string) string {
	return fmt.Sprintf(`-WindowStyle Hidden -NoProfile -NonInteractive -ExecutionPolicy Bypass -File "%s"`, scriptPath)
}

func createWindowsTask(scriptPath string) error {
	out, err := runPowerShell(fmt.Sprintf(`
$action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument %s
$trigger = New-ScheduledTaskTrigger -AtLogOn -User $env:USERNAME
$principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -LogonType Interactive -RunLevel Limited
Register-ScheduledTask -TaskName %s -Action $action -Trigger $trigger -Principal $principal -Force | Out-Null
`, powerShellLiteral(windowsTaskActionArgs(scriptPath)), powerShellLiteral(windowsTaskName)))
	if err != nil {
		return fmt.Errorf("register scheduled task: %s (%w)", out, err)
	}
	return nil
}

func windowsTaskMatchesAction(scriptPath string) bool {
	out, err := runPowerShell(fmt.Sprintf(`
$task = Get-ScheduledTask -TaskName %s -ErrorAction SilentlyContinue
if ($null -eq $task) { exit 1 }
$expectedArgs = %s
foreach ($action in $task.Actions) {
	if (($action.Execute -ieq 'powershell.exe') -and ($action.Arguments -eq $expectedArgs)) {
		Write-Output 'true'
		exit 0
	}
}
exit 1
`, powerShellLiteral(windowsTaskName), powerShellLiteral(windowsTaskActionArgs(scriptPath))))
	return err == nil && strings.EqualFold(strings.TrimSpace(out), "true")

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Read the %s output in the error — it contains the exact PowerShell failure message.
  2. Verify powershell.exe is available: `powershell.exe -NoProfile -Command "echo ok"`.
  3. Run the install from an interactive user session (the principal requires an interactive logon user), not from a service or SYSTEM context.
  4. Register the task manually with the same command in a PowerShell window to see the full error.
  5. Check group policy / antivirus restrictions on Register-ScheduledTask.

Example fix

// reproduce manually to see the real reason
powershell -NoProfile -Command "Register-ScheduledTask -TaskName cc-connect -Action (New-ScheduledTaskAction -Execute powershell.exe -Argument '-File script.ps1') -Trigger (New-ScheduledTaskTrigger -AtLogOn) -Principal (New-ScheduledTaskPrincipal -UserId $env:USERNAME -LogonType Interactive -RunLevel Limited) -Force"
Defensive patterns

Strategy: validation

Validate before calling

if _, err := exec.LookPath("powershell"); err != nil {
	return fmt.Errorf("powershell.exe not found on PATH")
}

Try / catch

if err := daemon.Install(scriptPath); err != nil {
	var msg string
	if strings.Contains(err.Error(), "register scheduled task") {
		fmt.Sscanf(err.Error(), "register scheduled task: %s", &msg) // captured PowerShell output
	}
	slog.Error("task registration failed; run install from an interactive session", "error", err)
}

Prevention

When it happens

Trigger: daemon.Install on Windows when the embedded PowerShell (New-ScheduledTaskAction / New-ScheduledTaskTrigger -AtLogOn / New-ScheduledTaskPrincipal -LogonType Interactive -RunLevel Limited / Register-ScheduledTask -Force) fails: powershell.exe not on PATH, exec error, or Register-ScheduledTask returning an error (access denied, invalid principal, policy).

Common situations: PowerShell missing or PATH broken on minimal Windows installs; running as SYSTEM/service account where Interactive logon principal is invalid; group policy restricting scheduled task registration; running in a non-interactive session.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/13262cf0ec58e447. Report an issue: GitHub.