{"record":{"id":"0976c8aeb0214786","repo":"coreybutler/nvm-windows","slug":"scheduling-error-v-s","errorCode":null,"errorMessage":"scheduling error: %v\n%s","messagePattern":"scheduling error: (.+?)\n(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/upgrade/register.go","lineNumber":170,"sourceCode":"schtasks /create /tn \"%s\" /tr \"cmd.exe /c %s\" /sc %s /st %s /F > %%output%% 2>&1\nif not errorlevel 0 (\n\techo ERROR: Failed to create scheduled task: exit code: %%errorlevel%% >> %%errorlog%%\n\ttype %%output%% >> %%errorlog%%\n\texit /b %%errorlevel%%\n)\n\t`, tmp, name, escapeBackslashes(command), strings.ToLower(interval), start)\n\n\terr = os.WriteFile(filepath.Join(tmp, \"schedule.bat\"), []byte(script), os.ModePerm)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"scheduling error: %v\", err)\n\t}\n\n\tcmd := exec.Command(filepath.Join(tmp, \"schedule.bat\"))\n\n\t// Capture standard output and standard error\n\tout, err := cmd.CombinedOutput()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"scheduling error: %v\\n%s\", err, out)\n\t}\n\n\t// fmt.Sprintf(`\"%s\" task scheduled successfully!`, name)\n\n\treturn nil\n}\n\nfunc UnscheduleTask(name string) error {\n\ttmp, err := os.MkdirTemp(\"\", \"nvm4w-registration-*\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"scheduling error: %v\", err)\n\t}\n\tdefer os.RemoveAll(tmp)\n\n\tscript := fmt.Sprintf(`\n@echo off\nset errorlog=\"error.log\"\nset output=\"%s\\output.log\"","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/coreybutler/nvm-windows/blob/5b18223ca19ff50d707f35410dbc6bd440a9f74d/src/upgrade/register.go#L152-L188","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Read the captured schtasks output embedded in the error — it names the exact OS complaint","Re-run the nvm operation from an elevated (administrator) terminal","Simplify the scheduled command: quote paths, remove shell metacharacters (&, |, >) from arguments","Manually reproduce: schtasks /create /tn <name> /tr \"cmd.exe /c <command>\" /sc <interval> /st 00:00 /F","Check that startTime (if supplied) matches HH:MM 24-hour format"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := ScheduleTask(name, cmd, interval, start); err != nil {\n    msg := err.Error()\n    if strings.Contains(msg, \"ERROR: Access is denied\") || strings.Contains(msg, \"access is denied\") {\n        // re-run from elevated context or prompt the user\n    }\n    log.Printf(\"schtasks output: %s\", msg) // embedded output names the real cause\n}","preventionTips":["Run task registration elevated","Quote all paths in the scheduled command and avoid shell metacharacters","Use HH:MM 24-hour start times","Reproduce with schtasks /create manually before automating"],"tags":["nvm-windows","schtasks","scheduled-tasks","windows","elevation"],"backgroundTag":null,"analyzedSha":"5b18223ca19ff50d707f35410dbc6bd440a9f74d","analyzedAt":"2026-08-15T10:06:51.428Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}