About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.
When the Task Scheduler Library shows Last Run Result as 0x1 for a task that works when you run it by hand, Task Scheduler did start the action. "Incorrect function" is the system text for error 1, not a Task Scheduler message. The value is the exit code the program or batch file returned: Microsoft's SQL Server page says the column "shows the exit code that the batch file returned". A program that exits with 1 reports failure in its own terms, so the job is to find what differs between your manual run and the task's run: the starting folder, the account, or the file names the script assumes.
What the message means
Microsoft's System Error Codes page lists ERROR_INVALID_FUNCTION, 1 (0x1), with the text "Incorrect function." Our own reading: that text names the number 1, not a faulty function. The number 1 reached Task Scheduler as the program's exit code.
The page on Task Scheduler constants lists the codes Task Scheduler itself returns, such as SCHED_S_TASK_HAS_NOT_RUN (0x00041303) for "The task has not yet run" and SCHED_S_TASK_TERMINATED (0x00041306). 0x1 is not among them. The same page notes that some codes are system codes and that net helpmsg decodes them: net helpmsg 1 returns the system text for code 1.
The SQL Server page gives a concrete case. Its examples use the -b option, and the page says "a value of 0x1 means that the backup command failed". It adds that without -b, sqlcmd "returns 0 even when the backup fails, and Task Scheduler reports the task as successful." So the same column can hide a failure or show one, depending on what the program returns.
Likely causes
Our own reading applies to the first three rows, which concern how a task resolves names when it runs; Microsoft's pages describe the Start in field and the System32 assumption of schtasks change.
| Cause | What you see | How to confirm |
|---|---|---|
| The script returns 1 because a relative file is not found | Works from its own folder, fails in the task | The task's action has an empty Start in value |
| The task runs as a different account | Works as you, fails as the run-as account | The run-as account in the verbose query differs from yours |
| The program is named without a path | The file is not found where the task looks | The Command in the task XML has no folder |
| A variable used in the action's path, arguments or Start in changed | Old value used | Microsoft's page: values are cached when the task engine starts |
| The script's own logic exits with 1 | Same result by hand when run as the task's account | The script's output shows the real error |
Prove the cause before changing anything
All of these only read.
1. Read the result as the task reports it. schtasks /query with /v adds the advanced properties, and the page describes /hresult as "Specifies the process exit code to be in HRESULT format."
schtasks /query /tn "\Nightly\Export" /fo LIST /v
schtasks /query /tn "\Nightly\Export" /fo LIST /v /hresult
Our own arithmetic: exit code 1 in HRESULT form is 0x80070001, which is 2147942401 in decimal (2,147,483,648 + 458,752 + 1).
2. Decode the number.
net helpmsg 1
3. Read the action's definition. Microsoft's schtasks query page says /xml outputs the task definitions in XML format, and the ExecAction.WorkingDirectory page names the WorkingDirectory element:
schtasks /query /tn "\Nightly\Export" /xml
Look at whether Command has a folder and whether WorkingDirectory exists. The verbose query in step 1 shows the run-as account. Microsoft's ExecAction.WorkingDirectory page says "the directory that contains either the executable file or the files that are used by the executable file", and says the path is checked "when the task is registered, not when this property is set".
4. Read the Start in field in the console. In Task Scheduler, open the task's properties, go to Actions, and edit the action. Microsoft's Purview page walks through the same Edit Action box; its labels are "Program/script", "Add arguments (optional)" and "Start in (optional)". Microsoft's Group Policy Preferences page says Start in sets "the working directory for the command being run (typically to ensure the correct resolution of any relative file names)", and "Do not include quotation marks or a trailing slash."
5. Check the service log. Microsoft's schtasks run page says to check the Task Scheduler Service transaction log, <Systemroot>\SchedLgU.txt, if a task does not run.
Fix
Change one thing, then run the task once. If the program itself is at fault, for example a script that exits with 1 when a share is unreachable, fix that script; the checks above only show where Task Scheduler's view and yours differ.
Set the starting folder
Use this where the script uses relative file names and Start in is empty.
First save the current state:
schtasks /query /tn "\Nightly\Export" /xml > Export-before.xml
Risk: the next step changes the folder the action starts in. Every file name in the script that is not a full path is then resolved against that folder, so a script that relied on another folder behaves differently on its next run.
In the Edit Action box, put the script's own folder in "Start in (optional)", for example C:\Scripts, with no quotation marks and no trailing slash, and select OK.
Only if you need to back out, and knowing that scripts which now rely on the new folder will resolve their file names against the old one again, open the same box and restore the Start in value that Export-before.xml shows in its WorkingDirectory element, or clear the box if the saved file has no such element. Then run schtasks /query /tn "\Nightly\Export" /xml and compare it with the saved file.
Give the program a full path
Microsoft's schtasks change page says that if the /tr value has no path, schtasks assumes the file is in the System32 directory under the system root. Use this where the Command in the saved XML is a bare file name.
First save the current state:
schtasks /query /tn "\Nightly\Export" /xml > Export-before.xml
Risk: the next command replaces the program the task runs. Microsoft's page says the specified program replaces the original program. The task then runs the file at the new path at its next trigger. Our own reading: the page describes /tr as a path and file name, so arguments saved in the action may have to be entered again afterwards.
Replace the program, using the full path of the file the task should start:
schtasks /change /tn "\Nightly\Export" /tr C:\Scripts\export.cmd
Only if you need to back out, and knowing that the program you set above is then no longer started, run the same command with the Command value from Export-before.xml.
Risk: the next command replaces the program the task runs with the one saved in Export-before.xml, and the program you set above is no longer started. The task runs the saved program at its next trigger.
schtasks /change /tn "\Nightly\Export" /tr <Command value from Export-before.xml>
The command restores only the program, so then open the Edit Action box, re-enter any arguments that Export-before.xml shows in its action, and query the task again.
The run-as account
If step 1 shows a different account from the one you tested with, Microsoft's schtasks change page lists /ru and /rp for changing the account and its password. Changing the account moves the task into another account's rights and profile, so decide who should own the job before touching it. Microsoft's batch-job page says the Log on as a batch job right is one that Task Scheduler grants automatically, and describes a task's account as logging on "as a batch job".
Example (illustrative): On app01, the task \Nightly\Export runs C:\Scripts\export.cmd as EXAMPLE\svc-export at 02:00. The script copies data.csv to D:\Share\ using the bare name data.csv. Run from C:\Scripts in a console, it succeeds. In Task Scheduler, Last Run Result is 0x1. The saved XML shows Command as C:\Scripts\export.cmd and no WorkingDirectory. The administrator sets Start in to C:\Scripts, runs the task, and the result column reads 0x0.
Confirm the fix
Running the task is itself an action, so save its state first.
First save the current state:
schtasks /query /tn "\Nightly\Export" /fo LIST /v > Export-result-before.txt
Risk: the next command starts the task now, with the same real effects as a scheduled run, such as copying files or sending data. A run cannot be taken back. Run it only when the job is safe to run at this time.
Run it:
schtasks /run /tn "\Nightly\Export"
Microsoft's page says the run operation "ignores the schedule, but uses the program file location, user account, and password saved in the task" and that it does not change the next scheduled run time. After a short wait, query again with /v; the result should read 0x0, and the output the job should make should exist.
What to watch afterwards
- A result of 0x0 shows only that the program returned 0. Check the output the job is meant to produce, as the SQL Server page does for its backups with the history in
msdb. - Have a program return a non-zero code on failure, as
sqlcmd -bdoes. Without it, the page notes, Task Scheduler reports success. - Re-check Start in and the program path after anyone moves the script folder.
Read next
Related articles you may want next.
- TroubleshootingGroup Policy Preferences scheduled task not applying: event 4098 "did not apply because it failed with error code" 0x80070005 Access is deniedA user GPP scheduled task fails with event 4098 and 0x80070005. Read the event, then clear the logged-on user's security context option.Read article
- TroubleshootingPowerShell "running scripts is disabled on this system": find which execution policy is blocking the scriptPowerShell says running scripts is disabled on this system. List the execution policy in every scope, then change the narrowest scope with a way back.Read article
- TroubleshootingPowerShell "The term is not recognized as the name of a cmdlet, function, script file, or operable program": the module is not loadedPowerShell says the term is not recognized as a cmdlet, function, script file or program. Check spelling, list modules, then import or install it.Read article
Risks and limits
- These commands have not been run or lab-tested.
- Task Scheduler's default working directory for an empty Start in is not established here, and the System Error Codes page lists error 1 without tying it to any one task fault.
- A run starts the real job. Pick a safe time.
- Microsoft's
schtasks changepage describes/tras a path and file name; where the saved XML shows arguments, the console is the place that shows them.
Sources
- Schedule and automate backups of SQL Server Express databases — Microsoft Learn, 9 September 2026, accessed 3 December 2026
- System Error Codes (0-499) — Microsoft Learn, 14 July 2025, accessed 3 December 2026
- Task Scheduler error and success constants — Microsoft Learn, 29 October 2024, accessed 3 December 2026
- schtasks query — Microsoft Learn, 16 February 2024, accessed 3 December 2026
- schtasks run — Microsoft Learn, 3 February 2023, accessed 3 December 2026
- schtasks change — Microsoft Learn, 3 February 2023, accessed 3 December 2026
- ExecAction.WorkingDirectory property — Microsoft Learn, 11 December 2020, accessed 3 December 2026
- ExecAction object — Microsoft Learn, 11 December 2020, accessed 3 December 2026
- Working with Control Panel Settings Preference Items Using the GPMC — Microsoft Learn, 2 September 2016, accessed 3 December 2026
- Set up a connector to import HR data — Microsoft Learn, 30 March 2026, accessed 3 December 2026
- Log on as a batch job — Microsoft Learn, 19 April 2017, accessed 3 December 2026
This article was originally published on .