{"record":{"id":"563322a48aa4f4d0","repo":"jdx/mise","slug":"schtasks-failed-printed","errorCode":null,"errorMessage":"`schtasks {}` failed: {printed}","messagePattern":"`schtasks (.+?)` failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/scheduled_tasks.rs","lineNumber":391,"sourceCode":"        }\n        std::fs::write(&staging, &rendered)?;\n        if let Err(err) = schtasks(&create).await {\n            let _ = std::fs::remove_file(&staging);\n            return Err(err);\n        }\n        // written, not renamed: a rename does not replace an existing\n        // definition on Windows\n        std::fs::write(&path, &rendered)?;\n        let _ = std::fs::remove_file(&staging);\n        if end_first {\n            // it may have exited between the query and now: the HRESULT\n            // says so in every locale; the message is matched as a fallback\n            let (status, printed) = schtasks_output(&end).await?;\n            if !status.success()\n                && status.code() != Some(SCHED_E_TASK_NOT_RUNNING)\n                && !end_error_is_noop(&printed)\n            {\n                bail!(\"`schtasks {}` failed: {printed}\", shell_words::join(&end));\n            }\n        }\n        if start {\n            schtasks(&run).await?;\n        }\n    }\n    Ok(())\n}\n\n/// Delete the task mise registered for `name`. Returns whether one existed.\npub(crate) async fn remove_task(name: &str, dry_run: bool) -> Result<bool> {\n    let task = task_name(name);\n    let path = definition_path(name);\n    if !exists(name).await? {\n        if path.exists() && !dry_run {\n            std::fs::remove_file(&path)?;\n        }\n        return Ok(false);","sourceCodeStart":373,"sourceCodeEnd":409,"githubUrl":"https://github.com/jdx/mise/blob/afd2eddd3a50c16190efc1c7e94404b48f72af57/src/system/scheduled_tasks.rs#L373-L409","documentation":"When applying enable/disable state changes to a scheduled task, the helper runs `schtasks /Change ...` and treats failure as fatal unless the exit code is SCHED_E_TASK_NOT_RUNNING or the printed output matches a known no-op error. Any other non-zero exit from schtasks surfaces as this error with the joined command and its output.","triggerScenarios":"Calling apply with start/stop (enable/disable or run/end) where schtasks_output returns a non-success status that is not the tolerated 'task not running' case — e.g. task name not found, access denied, or malformed task definition.","commonSituations":"Trying to end a task that is not running in a locale/message not covered by end_error_is_noop; insufficient privileges (service not run elevated); task deleted between check and change; corrupted task XML after a Windows update.","solutions":["Read the `printed` output in the error: fix the underlying cause it reports (name mismatch, missing task, permissions).","Run the operation elevated / as the correct user if output indicates access denied.","If the task no longer exists, recreate or reinstall the service/task definition before changing its state.","Verify the exact task name (including the 'mise\\' folder prefix handling) matches the installed task."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-check the task exists and you have rights before changing state\n// schtasks /Query /TN \"mise\\\\my-task\" -> non-zero means fix name/permissions first","typeGuard":null,"tryCatchPattern":"match apply_state_change(task) {\n    Err(e) if e.to_string().contains(\"schtasks\") => {\n        log::error!(\"schtasks change failed: {e}; check task name, elevation, and task existence\");\n        // inspect the embedded `printed` output for the OS-level reason before retrying\n    }\n    Err(e) => return Err(e),\n    Ok(v) => Ok(v),\n}","preventionTips":["Run task state changes elevated or under the account that owns the task","Confirm the task name (including the mise\\\\ prefix) before enabling/disabling/ending","Treat SCHED_E_TASK_NOT_RUNNING as success for /End and handle it in your wrapper","Re-create the task definition if schtasks reports corruption or missing task"],"tags":["windows","scheduled-tasks","process"],"backgroundTag":"command-failed","analyzedSha":"afd2eddd3a50c16190efc1c7e94404b48f72af57","analyzedAt":"2026-09-09T01:38:25.179Z","contentChangedAt":"2026-09-09T01:38:25.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}