coreybutler/nvm-windows · error

scheduling error: %v %s

Error message

scheduling error: %v
%s

What it means

ScheduleTask() ran the generated schedule.bat (schtasks /create ...) via CombinedOutput and the script returned a non-zero exit code; the message includes both the process error and the combined stdout/stderr of schtasks. This is the actual Windows Task Scheduler rejecting the task creation.

Source

Thrown at src/upgrade/register.go:170

schtasks /create /tn "%s" /tr "cmd.exe /c %s" /sc %s /st %s /F > %%output%% 2>&1
if not errorlevel 0 (
	echo ERROR: Failed to create scheduled task: exit code: %%errorlevel%% >> %%errorlog%%
	type %%output%% >> %%errorlog%%
	exit /b %%errorlevel%%
)
	`, tmp, name, escapeBackslashes(command), strings.ToLower(interval), start)

	err = os.WriteFile(filepath.Join(tmp, "schedule.bat"), []byte(script), os.ModePerm)
	if err != nil {
		return fmt.Errorf("scheduling error: %v", err)
	}

	cmd := exec.Command(filepath.Join(tmp, "schedule.bat"))

	// Capture standard output and standard error
	out, err := cmd.CombinedOutput()
	if err != nil {
		return fmt.Errorf("scheduling error: %v\n%s", err, out)
	}

	// fmt.Sprintf(`"%s" task scheduled successfully!`, name)

	return nil
}

func UnscheduleTask(name string) error {
	tmp, err := os.MkdirTemp("", "nvm4w-registration-*")
	if err != nil {
		return fmt.Errorf("scheduling error: %v", err)
	}
	defer os.RemoveAll(tmp)

	script := fmt.Sprintf(`
@echo off
set errorlog="error.log"
set output="%s\output.log"

View on GitHub (pinned to 5b18223ca1)

Solutions

  1. Read the captured schtasks output embedded in the error — it names the exact OS complaint
  2. Re-run the nvm operation from an elevated (administrator) terminal
  3. Simplify the scheduled command: quote paths, remove shell metacharacters (&, |, >) from arguments
  4. Manually reproduce: schtasks /create /tn <name> /tr "cmd.exe /c <command>" /sc <interval> /st 00:00 /F
  5. Check that startTime (if supplied) matches HH:MM 24-hour format
Defensive patterns

Strategy: try-catch

Try / catch

if err := ScheduleTask(name, cmd, interval, start); err != nil {
    msg := err.Error()
    if strings.Contains(msg, "ERROR: Access is denied") || strings.Contains(msg, "access is denied") {
        // re-run from elevated context or prompt the user
    }
    log.Printf("schtasks output: %s", msg) // embedded output names the real cause
}

Prevention

When it happens

Trigger: schtasks /create failing: access denied creating a task under a different user without /RU+/RP, invalid start time format, the /TR command path containing unescaped characters, or schedule/modifier combos requiring extra flags (e.g. EVENT needs /EC and /ID).

Common situations: Running without elevation when the task needs higher privileges; a command argument with spaces or ampersands breaking the cmd.exe /c quoting; start time not in HH:MM 24h format; group policy restricting task creation.

Related errors


AI-assisted analysis of coreybutler/nvm-windows@5b18223ca1 (2026-08-15). Data as JSON: /api/errors/0976c8aeb0214786. Report an issue: GitHub.