How to Fix Task Scheduler Last Run Result 0x1

Last Run Result 0x1 in Windows Task Scheduler usually means the launched program or script returned exit code 1, not that Task Scheduler itself is broken. Common causes include an incorrect working directory, different account permissions, unavailable network resources, or a script command returning an unexpected result. Use the symptoms below to choose where to investigate before changing the task.

Symptom Likely Cause First Check
The script works when double-clicked but fails as a scheduled task Different working directory or environment Set Start in and use absolute paths
The log shows a missing script, executable, or input file Incorrect path, quoting, or arguments Separate the executable from its arguments
The task works only while you are logged on Interactive-session dependency or different credentials Check the task account and unattended requirements
Local files work, but network files fail Unavailable mapped drive or insufficient network permissions Use a UNC path and verify share access
Copying or cleanup finishes, but the task reports failure A later command returns a nonzero result Capture each important command’s result
An IIS cleanup fails only when there is nothing to delete An expected forfiles no-match condition Handle an empty selection without hiding other errors

What Task Scheduler’s Last Run Result Means

For a task that successfully launches a program, Last Run Result generally reflects that program’s exit status. If the action starts a command interpreter, the result can come from the batch script it runs. If it starts PowerShell, the result comes from the PowerShell process.

That distinction matters: a program can start correctly and then fail because it cannot read a configuration file, write a log, authenticate to a share, or find a required dependency.

A generic Windows error-code lookup may label this value “Incorrect function.” That description is not a diagnosis for every scheduled program. Applications define their own exit-code meanings, so the task’s history and application output are more useful than the label alone.

There are two different problems to distinguish:

  • The action did not start: investigate the executable, task credentials, and launch permissions.
  • The action started and returned an unsuccessful result: investigate the script, application logs, and execution environment.

An “action completed” event means the process ended. The intended work might not have succeeded.

How to Fix Task Scheduler Exit Code 1

Exit code 1 is addressed by enabling history, correcting the task action and working directory, and capturing the actual error.

Step 1: Enable History and Identify What Failed

  1. Open Task Scheduler and select Enable All Tasks History in the Actions pane if history is disabled. Enabling it records future activity; it does not reconstruct earlier runs.
  2. Select the affected task and open its History tab.
  3. Before reproducing the problem, confirm that another run will not cause unwanted deletions, duplicate imports, or overlapping work.
  4. Right-click the task, select Run, and inspect the new history entries after it finishes.

Look for whether Task Scheduler launched the action and whether the launched process returned a result. If launch failed, focus on the action’s executable and account. If the program ran, capture its output rather than repeatedly changing scheduler settings.

For a task with multiple actions, inspect each action’s events.

Step 2: Correct the Action and Working Directory

  1. Open the task’s Properties > Actions, select the action, and choose Edit.
  2. Put the executable in Program/script, its parameters in Add arguments, and the working folder in Start in.
  3. Replace the example locations below with your actual paths, then save the action.

For a batch file

Use the command interpreter as Program/script:

C:\Windows\System32\cmd.exe

Use this value for Add arguments:

/c ""C:\Jobs\Cleanup-Logs.cmd""

Set Start in to the folder containing the script:

C:\Jobs

The outer and inner quotation marks in the arguments handle the command-interpreter invocation and the script path. Do not include the script filename or surrounding quotation marks in Start in, even when that folder name contains spaces.

For a Windows PowerShell script, set Program/script to the Windows PowerShell executable:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

Use these Add arguments:

-NoProfile -NonInteractive -File "C:\Jobs\Cleanup-Logs.ps1"

Set Start in:

C:\Jobs

Use -File for a saved PowerShell script rather than wrapping the invocation in -Command. The latter is valid for command expressions, but it introduces unnecessary quoting complexity for this job.

-NoProfile prevents dependencies on an interactive PowerShell profile, while -NonInteractive prevents the job from waiting for user input. If the script needs configuration normally supplied by a profile, load that configuration explicitly.

Do not add an execution-policy bypass as a general repair. If the log identifies a policy restriction, resolve the script-signing or policy requirement through your organization’s approved process.

Setting the working directory fixes relative-path assumptions. Absolute paths for input files, output files, and external executables make the task less dependent on its environment.

Step 3: Capture the Actual Error

  1. Create a log folder, such as C:\Jobs\Logs, and give the task account permission to write there.
  2. Save the following diagnostic wrapper as C:\Jobs\Run-Cleanup.cmd.
  3. Configure the task to run the wrapper, then inspect the log after a run.

For a batch-file action, use:

@echo off
call "C:\Jobs\Cleanup-Logs.cmd" >>"C:\Jobs\Logs\cleanup.log" 2>&1
set "rc=%ERRORLEVEL%"
exit /b %rc%

Change the task’s Add arguments to:

/c ""C:\Jobs\Run-Cleanup.cmd""

The wrapper appends standard output and standard error to the same file. It also captures the script’s exit status immediately and returns it, rather than turning every run into apparent success.

For a PowerShell script, set Program/script to C:\Windows\System32\cmd.exe and Add arguments to /c “”C:\Jobs\Run-Cleanup.cmd””. Save this batch-wrapper content as C:\Jobs\Run-Cleanup.cmd:

@echo off
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -NonInteractive -File "C:\Jobs\Cleanup-Logs.ps1" >>"C:\Jobs\Logs\cleanup.log" 2>&1
set "rc=%ERRORLEVEL%"
exit /b %rc%

Run the task and read C:\Jobs\Logs\cleanup.log. Look for the first meaningful failure, not just the last line. Typical messages identify a missing file, access denial, unavailable command, authentication failure, or empty file selection.

If no log appears, verify that the log directory exists and is writable before concluding that the script never launched. The redirection itself can fail.

Step 4: Check the Task Account and Unattended Environment

  1. In the task’s General tab, confirm which account runs it.
  2. Verify that this account can read the script and inputs, execute dependencies, and write the outputs and logs.
  3. Check any network access separately from local access.
  4. If necessary, test the interactive and unattended configurations, then restore the intended production setting.

A script working in your own terminal proves only that it works under your account and session.

For network resources, use a UNC path such as \\server\share\folder rather than relying on a mapped drive letter. Drive mappings belong to logon sessions and may be absent from an unattended task. Both share permissions and file-system permissions must allow the operation, and the task’s authentication method must support network access.

Temporarily selecting Run only when user is logged on can help identify a session dependency. If that changes the outcome, investigate prompts, desktop applications, profile-loaded configuration, mapped drives, and credentials. The script may not be ready for unattended use.

Enable Run with highest privileges only when the operation genuinely requires elevation. It is not a substitute for correct file permissions and does not give an ordinary account administrator rights.

After correcting the dependency, restore Run whether user is logged on or not if that is how the task must operate.

Step 5: Fix the Logged Failure and Retest

  1. Make the smallest change supported by the error message.
  2. Run the task through Task Scheduler, not only through a terminal.
  3. Confirm both the intended output and the new result.
  4. For unattended jobs, verify a scheduled run while the account is logged off.

For a missing dependency, use its full executable path or configure the required environment explicitly. For access denial, grant only the permissions the operation needs. For a failed application command, resolve that application’s error rather than changing scheduler options.

In a multi-command script, capture the result immediately after each important operation. A later successful command can obscure an earlier failure, just as a later harmless condition can make otherwise successful work appear unsuccessful.

If the log shows that cleanup found no eligible files, handle that condition deliberately.

When Forfiles Finds No Matching Logs

A task can finish its main work and still report failure because a later command supplies the final exit result.

A cleanup configured to remove IIS logs older than 14 days can return an unsuccessful result simply because no files match. A preceding copy operation may have completed normally.

Confirm the actual retention cutoff in the batch file’s forfiles /d argument. It is a script setting, not a Task Scheduler default.

Preview the File Selection Without Deleting Anything

Use a non-destructive command to inspect which log files qualify:

forfiles /p "C:\inetpub\logs\LogFiles" /s /m *.log /d -14 /c "cmd /c echo @path"

This prints matching paths rather than deleting files. Microsoft’s forfiles documentation defines the date filter in terms of files’ last-modified dates.

Check that:

  • The directory exists and is the intended IIS log location.
  • The task account can enumerate it.
  • The filename filter matches your logs.
  • An empty selection is acceptable for this cleanup.

Use a fully qualified directory path, such as C:\inetpub\logs\LogFiles, for the forfiles /p argument. A path such as C:inetpublogsLogFiles is not equivalent: without the backslash after the drive letter, it is drive-relative.

Make an Empty Cleanup a Successful No-Op

Do not treat every unsuccessful forfiles result as “nothing to delete.” Missing directories and permission failures also need attention.

One way to distinguish an empty selection from a real failure is to implement the cleanup in PowerShell. This example previews deletion, treats no matching logs as normal, and returns failure for exceptions:

$ErrorActionPreference = 'Stop'
try {
    $root = 'C:\inetpub\logs\LogFiles'
    $cutoff = (Get-Date).Date.AddDays(-14)
    $files = @(
        Get-ChildItem -LiteralPath $root -Filter '*.log' -File -Recurse |
            Where-Object { $_.LastWriteTime.Date -le $cutoff }
    )
    foreach ($file in $files) {
        Remove-Item -LiteralPath $file.FullName -WhatIf
    }
    Write-Output "Matching logs: $($files.Count)"
    exit 0
}
catch {
    Write-Error $_ -ErrorAction Continue
    exit 1
}

To use this replacement:

  1. Back up the existing cleanup script and confirm that the directory, log-file filter, and retention policy are appropriate.
  2. Save the example as the PowerShell script configured in the task’s action.
  3. Run the task with -WhatIf present and inspect the proposed deletions in its captured output.
  4. Once the selection is correct and deletion is approved, remove -WhatIf, save the script, and run the task again.
  5. Verify that only the intended logs were removed and that an empty selection completes successfully.

This approach does not infer success from an error message. It explicitly allows an empty collection while preserving failures such as unreadable directories or unsuccessful deletions.

How to Return the Correct Batch Exit Code

A batch file should report the outcome of the whole job, not accidentally inherit whichever command happened to run last.

Preserve Genuine Failures

Capture an important command’s exit status immediately. Decide whether that status means success using the command’s own documented behavior, then propagate a genuine failure to Task Scheduler.

Do not append a success exit to an otherwise unchecked script. That can make a failed backup, incomplete copy, or denied deletion appear healthy.

Return Success After an Acceptable Result

After an expected condition has been handled and all required operations have succeeded, a batch script can explicitly finish with:

exit /b 0

Place it at the end of the successful execution path. A branch handling an actual failure must return the failure instead.

Run the task afterward and check its output as well as its reported status. Changing the exit code is appropriate only when it accurately represents the work.

Avoid the ERRORLEVEL Variable Trap

Do not use the following as a substitute for returning success:

set ERRORLEVEL=0

Although this is sometimes suggested immediately after an acceptable command result, it sets an environment variable named ERRORLEVEL; it does not reliably reset the command interpreter’s internal error status. It can also shadow the dynamic %ERRORLEVEL% value and make subsequent checks misleading.

If that assignment is already in the script, remove it and use explicit exit handling. Suppressing error output likewise does not turn a failed command into a successful one.

Verify the Scheduled Task and Keep It Reliable

After correcting the task or its error handling, a conventional successful result is 0 or 0x0. An application with a different exit-code convention needs interpretation according to that application’s documentation.

Before considering the repair complete, verify that:

  • The intended work happened: the expected files, records, or other outputs are present.
  • The log is clean: no important failure was hidden by a later command.
  • The scheduled environment works: the task succeeds under its configured account without interactive help.
  • Failures remain visible: the script still reports genuine errors instead of always reporting success.

Keep absolute paths, a defined working directory, useful logs, and explicit exit handling in the production task. Once the manual Task Scheduler run is correct, let the normal trigger run it and inspect that run’s output and history too.

Frequently Asked Questions

What Does Task Scheduler Result 0x2 Mean?

0x2 is hexadecimal for exit code 2; when interpreted as the Windows system error, it means “The system cannot find the file specified.” Check the executable, script, input paths, and working directory. If the application launched successfully and returned that value itself, its documentation determines the meaning.

What Does Task Scheduler Code 0x41301 Mean?

0x41301 means the task is currently running. It is a status, not a completed failure result. If the task remains running unexpectedly, inspect its logs and processes for a prompt, blocked network request, or application that has not exited.

Is a Robocopy Exit Code of 1 a Failure?

No: Robocopy exit code 1 means files were copied successfully. Robocopy uses a richer result scheme than the usual convention that every nonzero value indicates failure. If a batch file wraps Robocopy, interpret its documented result before choosing the exit status to return to Task Scheduler.