Batch File From Scheduled Task Returns Code 2147942401

Siddharth Bishnoi Jun 28, 2022
  1. Understand the Error
  2. Possible Causes of the Error
  3. Ways to Solve the Error
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.

  1. It may be due to a mistake in your Batch file or while scheduling a task.
  2. 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.
  3. If the user is logged in and it still shows the error, it may be because of not providing enough privileges.
  4. Another possible reason for this error code may be the system path issue.

Ways to Solve the Error

  1. Assigning special privilege

    Type Windows+R to open the Run window and type secpol.msc /s to open the Local Security Policy window.

    open run tab

    Now, navigate to Local Policies > User Rights Assignment > Log on as a batch job. Double-click the Log on as a batch job to open the Properties window.

    log on as a batch job

    Click the Add User or Group button to add the relevant users.

    Properties window-batch job

    Add the username in the text box and click on OK.

    add users

    The scheduled task will run the Batch file even if the user is not logged in.

  2. Provide the highest privileges

    When creating a task, choose Create Task instead of Create Basic Task, especially for servers, as it gives you more options for server type, as shown below.

    create a task

    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.

    run task with highest privileges

    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.

    change user or group

  3. Add directory path via the Start in option

    Another way of solving the error code (0x1) is by assigning the directory path. Right-click on the task and click on Properties to open the Properties window.

    action tab-properties window

    Under the Actions tab, double-click on the action Start a program and add the Batch file’s directory in the Start in (optional): textbox.

    add batch file directory

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.

Related Article - Batch Error