Solution to the problem of returning 0x1 when the Windows 2008 task plan fails to execute a bat script

Solution to the problem of returning 0x1 when the Windows 2008 task plan fails to execute a bat script

Test environment:

C:\>systeminfo | findstr /c:"OS Name"
OS Name: Microsoft Windows Server 2008 R2 Enterprise

Many people encounter this problem when creating a task schedule to execute a bat file in Windows 2008: the status code returned after the task schedule is executed is 0x1 instead of the normal 0x0

I was also stuck with this problem today and spent almost a day troubleshooting it. Everything works fine when executing the bat script alone, and there is no problem executing the bat script in the Windows 2003 task schedule, but it does not work as long as it is placed in the Windows 2008 task schedule. After searching on domestic and foreign websites, I finally collected all the precautions. The steps are summarized as follows:

1. Confirm that the password of the user who wants to execute the task plan has not expired. If conditions permit, you can set the password to never expire to avoid unnecessary trouble.

The Chinese system has a password that never expires option

2. Open the Task Manager, right-click Task Scheduler Library, and select Create Task. Do not select Create Basic Task here.

3. In the General tab, select Run whether user is logged on or not, check Run with highest privileges, and then select Windows Server 2003 from the drop-down list. Do not select Windows Server 2008.

The Chinese system corresponds to the following figure

4. There is nothing special in the Triggers tab. Just set the execution time according to your needs.

5. In the Actions tab, fill in the script name in the Program/script input box. Do not include the path here. In the Start in input box, fill in the path where the script is located. Do not add quotation marks here.

6. Add a line at the end of the bat script:

Click (here) to collapse or expand

exit /b 0

If you do not explicitly specify an exit code, Task Scheduler will assume that the script execution has failed.

Versions prior to Window Server 2012 do not require a path to execute scheduled tasks

The version after Windows Server 2012 needs to set the path to execute the scheduled task. The batch program can be run normally by double-clicking it, but the error code 0x1 is not reported when it is put into the Windows scheduled task.

Cause of the error: The batch script in the program and script has a directory structure, but the path to the directory where the batch script is located is not configured at the start

The above is the detailed solution to the problem that the Windows 2008 task plan fails to execute the bat script and returns 0x1. For more information about win2008 bat script fails to return 0x1, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Solution to the problem of batch processing failure in Windows 2008 r2 task scheduler

<<:  Summary of Mysql update multi-table joint update method

>>:  This article takes you into the world of js data types and data structures

Recommend

Detailed explanation of MySQL 8.0 atomic DDL syntax

Table of contents 01 Introduction to Atomic DDL 0...

Vue.js uses Element-ui to implement the navigation menu

This article shares the specific code for impleme...

7 Best VSCode Extensions for Vue Developers

Adding the right VS Code extension to Visual Stud...

Specific use of pthread_create in linux to create threads

pthread_create function Function Introduction pth...

Mysql delete duplicate data to keep the smallest id solution

Search online to delete duplicate data and keep t...

More popular and creative dark background web design examples

Dark background style page design is very popular...

Understanding MySQL precompilation in one article

1. Benefits of precompilation We have all used th...

MySQL index usage instructions (single-column index and multi-column index)

1. Single column index Choosing which columns to ...

Ubuntu 20.04 how to modify the IP address example

illustrate: Today, when continuing the last offic...

Four ways to combine CSS and HTML

(1) Each HTML tag has an attribute style, which c...

Detailed explanation of JS memory space

Table of contents Overview 1. Stack and Heap 2. V...

Why is it slow when using limit and offset paging scenarios?

Let’s start with a question Five years ago when I...

Analyzing the node event loop and message queue

Table of contents What is async? Why do we need a...