Batch File From Scheduled Task Returns Code 2147942401
Windows Task Scheduler is an application that automates tasks and launches programs or scripts at specified intervals. It is an easy-to-use application with just a few clicks.
But when you run a Batch file through Windows Task Scheduler, sometimes it may return with errors. The most common error is the return code (0x1)
.
There are many reasons why this error occurs. When you schedule a task to run a Batch file, it may result in the return code 2147942401
.
However, when you manually run the task, it will work fine and run with a return code (0x0)
.
This tutorial will illustrate different ways to solve the error task successfully completed with the return code 2147942401
.
Understand the Error
The error codes for Windows Task Scheduler are listed in hexadecimal numbers. The error here is 2147942401
when converted to hexadecimal, resulting in 0X80070001
.
This error is defined as an incorrect function
or illegal function
. Though this error code is not listed in MSDN, it is a common error many users face when using Task Scheduler to run Batch files.
Possible Causes of the Error
The error code may occur due to many possible reasons.
- It may be due to a mistake in your Batch file or while scheduling a task.
- A scheduled task will only run when the user who created and scheduled the task is logged on. However, you can change it to run when the user is not logged on by special privilege,
Log on as a batch job
. - If the user is logged in and it still shows the error, it may be because of not providing enough privileges.
- Another possible reason for this error code may be the system path issue.
Ways to Solve the Error
-
Assigning special privilege
Type Windows+R to open the
Run
window and typesecpol.msc /s
to open theLocal Security Policy
window.Now, navigate to
Local Policies
>User Rights Assignment
>Log on as a batch job
. Double-click theLog on as a batch job
to open theProperties
window.Click the
Add User or Group
button to add the relevant users.Add the username in the text box and click on
OK
.The scheduled task will run the Batch file even if the user is not logged in.
-
Provide the highest privileges
When creating a task, choose
Create Task
instead ofCreate Basic Task
, especially for servers, as it gives you more options for server type, as shown below.By default, it is set to
Windows Vista, Windows Server 2008
. If you are using Windows 10, choose Windows 10 from the configured list.To set the task to run with the highest privileges, check the box labeled
Run with highest privileges
. The user should have the necessary privileges to execute the commands in the Batch file.Otherwise, it will show the task as completed successfully with return code
2147942401
.Also, the user account should be taken care of if you use it on a server. The Batch should not execute commands under the user account on the local machine.
While creating a task, click on
Change User or Group
and add the relevant user even if you’re already logged in with the same user. -
Add directory path via the
Start in
optionAnother way of solving the error code
(0x1)
is by assigning the directory path. Right-click on the task and click onProperties
to open theProperties
window.Under the
Actions
tab, double-click on the actionStart a program
and add the Batch file’s directory in theStart in (optional):
textbox.
So, we discussed three ways to solve the error task successfully completed with the return code 2147942401
. There are several possible reasons why this error appears, so if one method doesn’t work, you should try another method as discussed above.