Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Solution to batch execution failure of Windows 2008 R2 Task Scheduler

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Recently encountered a strange phenomenon, when doing a regular backup of a system using the non-system native Rsync command, but manual startup is no problem, and very much look forward to batch on multiple hosts, what to do? There is no problem with executing the task plan in this way under Windows Server 2003, but there is an accident under Windows Server 2008 R2.

Normally our task plan will have a feedback value, which can be used to determine whether the task plan worked properly last time (detailed link: http://support.microsoft.com/kb/267031/).

Code 0 or 0x0: the operation completed successfully.

Code 1 or 0x1: the function called is incorrect or an unknown function is called.

Code 10 or 0xa: the environment is incorrect.

Code 0x8009000f: general access denied

Figure 1 saw that the result of the last run was non-zero

This non-zero situation indicates that it is unacceptable.

I see an error message like this by setting a breakpoint on this batch.

Figure 2 adds Pause to the batch to make breakpoints to view error messages

Obviously, this rsync is not a program and file that comes with the system, so it cannot be called directly by the system. Guess it has to do with environment variables. Look carefully for the task planning options under Windows Server 2008 R2, and I see this place to fill in the blanks.

Figure 3 starts with (optional) item

I fill in this as the directory where the script is located, run the task plan again, get a success mark, and receive the corresponding backup content on the server side of the service.

In retrospect, the task plans of the two versions of the operating system are different. There are not many items to choose from under Windows Server 2003, but by default he will start by filling in and use the directory one level above the script.

The following Figure 4 Windows Server 2003 starts from, and is filled in by default

Therefore, it is recommended that the task planning of Nt6 core-based systems such as Windows Server 2008, 2012 should start with the following settings.

The following are the methods provided by other netizens

The second solution:

1. When creating a task plan, select "run regardless of whether the user is logged in or not", "run with the highest permissions" and configure with "Windows Server 2008 R2" in the General tab.

2. Start from (optional) in the operation tab to fill in the directory where the bat batch file is located. Windows 2003 automatically brings the bat batch file when you select it, but 2008 will not. Although it is optional, if it is left empty, the execution will fail.

3. When all the information is completed, you need to enter the password of the user account under which the task is run.

The third solution:

Below I would like to post a complete icon of the planned task:

Create a scheduled task

Customize the execution time of scheduled tasks

Schedule task action 1 (this situation is consistent with a single executable program or if the script does not call the database)

Scheduled task operation 2 (this situation is in line with the situation that the running program needs to call the directory database, PS: this all-in-all bar seems to be j

You can do it by default later.

The problem is that the options for editing operations start with the (optional) option.

It's ironic to find out the real problem.

The purpose of posting this post is to give you a well-documented suggestion that there are problems. Haha, you can also make a mark in case you forget.

The fourth solution:

Today, a new scheduled task is created in Windows Server 2008, which executes the sql command in the bat file of the scheduled task.

As a result, I checked the history of scheduled tasks and found that it was stuck.

Prompt that the scheduled task has been started, but the operation in bat has not been performed

At first, I suspected that there was an error in the bat file, but I changed it to the simplest command to open notepad, notepad, and found that the problem still existed.

Later, it was found that there was a very interesting place. When you create a new scheduled task, you have two options: create a basic task and create a task.

Before, it was the basic task that was created, and then it was replaced by the task of creation.

And then, the problem is solved.

The fifth solution:

Create a new administrator account and run it with the new account.

The sixth method: it is actually a supplement to the second method.

Solution:

As shown in the figure: the editing task adds the starting position of the batch file, such as: in d:\ aa.bat

Then the starting position is: d:\ Note: there can be no quotation marks in the path.

Here is a quote from the Internet:

There must be no problem with the batch file. When it was added to the scheduled task, it was found that it was not backed up properly and was not copied to the network mapping disk.

Output the bat file to the file, I wanted to see the log, but it didn't execute properly.

Google for a while, found that many netizens have similar questions, but no one gave the answer.

Luckily, I found a post discussed by netizens on Microsoft's official forum, which almost solved my problem.

Http://social.technet.microsoft.com/Forums/en-US/winservermanager/thread/d47d116e-10b9-44f0-9a30-7406c86c2fbe/ has a wonderful technical exchange.

For me, there are two problems.

1. A.bat deals with backup database. The content of b.bat is a.bat > D:/abc/1.log. B.bat is added to the scheduled task to debug whether the scheduled task is successful or not. (manually executed separately and successfully each time) the result is that 1.log does not output and returns 2; www.jb51.net in the planned task.

2Jar a.bat copies the backed-up data to the network mapping disk, such as Z disk, and the scheduled tasks are not executed every time, and it is also good to run the script manually.

Follow the tips given in the above forum:

2) Make sure that the task is set to "start in" the folder that contains the batch file: open the task properties, click on the "actions" tab, click on the action and then the "edit" button at the bottom. In the "Edit Action" Window there is a field for "start in (optional)" that you set to the path to the batch file.

Be sure to fill in the path of the batch in actions-> Edit actions-> start from (optional). This trick solves the first problem.

NET USE W: / DELETE

NET USE W: / / myserver/myfolder / PERSISTENT:YES

This is the key to solving the second problem, which requires the above two lines of commands before performing a copy or creating a new folder. Details: make sure that the network mapping disk is disconnected through the menu operation in my computer interface; the Windows server 2008 user management page has a network password management, if filled in, net use w:. There is no need to enter a password and user name for this command.

This trick solves the second problem.

Add: do not use double quotation marks for paths in batch files and "start from (optional)"

The seventh method:

Task Scheduler using windows server 2008 R2 needs to start the service Task Scheduler service

Windows server 2008 R2 Task Scheduler service is disabled by default and startup types cannot be switched

Solution: modify the value of the start key under the registry HKEY_LOCAL_MACHINE\ SYSTEM\ CurrentControlSet\ services\ Schedule to 2

Restart the server after modification, and the task scheduler can be added.

The eighth method:

Network environment: windows2003+windows2008.

Description: using mapping drive Z: mapping a directory of win2008 within win2003

Create the file in the bat file copy Z: in win2003, and schedule the task and execute it regularly in bat.

There is no problem for the command line to execute bat directly, but failed to execute the task plan.

The final solution is to refer to the following article and add it to the bat file:

NET USE Z:\\ XXX.XXX.XXX.XXX\ D$\ XXXX "Password" / User: "Administrator"

-

Also: map drive ZRV under win7, add task plan execution bat file Copy Z:\. No problem,

There is no bug. Net use that needs to be manually added.

After restarting Win7, the task plan disappears, but the task schedule created by other programs exists

Finally, through the exclusion check, it is found that it is due to 360 software! Both bat and job files need to be added to the whitelist.

Several Solutions to the failure of Task scheduling to run batch Files

Windows task planning and BAT batch files are tools that we often use, a task that can help us carry out scheduled tasks on a regular basis.

One can help us execute a series of pre-programmed commands at a time. In the maintenance of the Windows system, we often need to use the task plan with the batch, that is, by setting the task plan, we regularly execute a series of commands and operations defined by the batch file. Sometimes, we may encounter situations where task scheduling and batch processing do not work together properly. For example, for the same batch file, we might run it manually (indicating that there is no error in the contents of the batch file), but cannot run as expected after adding the batch file as a task schedule. In the Microsoft Chinese Forum, the author collected several methods to solve the problem that task planning and batch processing can not work together, hoping to help you to refer to similar problems. 1. Set the user identity and permissions to execute the batch correctly in the task plan. When we add a new task to the task schedule, one of the steps is to specify the user account under which the task is running and to enter the password of the user account for confirmation. If the user account identity or permissions set by the task schedule are different from the user account when we run the batch file manually, it is possible that the result of running the batch as a task schedule is different from that of running the same batch manually. For example, suppose a batch involves a command that requires administrator privileges or a profile for a specific user account to function properly, if the task schedule for this batch is specified as a non-administrator account or a user account that does not have the appropriate user configuration, then the batch is likely to fail to achieve its desired results when running as a task schedule. Therefore, when we add a task schedule and want to run the batch with the identity and privileges of another user account, be sure to check in the add New Task wizard that the identity and permissions of the user account running the batch meet the requirements for running this batch. two。 Use a shortcut to specify the starting location for the batch. Some batch files require us to set a specific "starting position" for them to run properly, otherwise you may encounter an error that the batch cannot find the specified path. When we execute the batch manually, whether we run the batch by double-clicking with the mouse in Explorer, or open the command prompt window first, and then execute the batch from the command prompt, the location of the folder currently open by the explorer and the prompt where the command prompt is currently located have automatically set the starting position for us to execute the batch. However, when we execute a batch as a task plan, the task plan cannot automatically specify the starting position needed to execute the batch, which may not achieve the desired results when executing the batch as a task plan. To solve this problem, we can first create a shortcut for the batch file, then modify the properties of the shortcut, set the correct "start location" in the General tab, and then add the task schedule. specify the new task as the shortcut file rather than the batch itself. In this way, the task schedule automatically executes a shortcut to the batch at the time specified by the task, and the corresponding batch has the correct starting position at run time. 3. Try to avoid too many quotation marks in batch content. If there are too many quotation marks in the contents of the batch file, that is, one or more commands and parameters in the batch are enlarged by quotation marks, this may not only be prone to errors when writing batch commands, but also cause the task plan of a particular version of Windows to fail to correctly identify the commands contained in the batch. This kind of problem is especially common when there are child quotes in a parent quote. According to information provided by Microsoft knowledge Base KB951246, this problem mainly exists in Windows Vista/Server 2008 systems. 4. Add a task schedule after converting a batch file to an executable file or script. Sometimes when the task plan fails to correctly execute part of the batch file, we can also try to convert the batch to an executable file or script in another format before adding it to the task plan. Although the conversion format carries out the same commands and tasks, converting a batch to an executable file or script can change the order and way in which tasks run, and sometimes solve the problem. Common format conversions for batch processing include converting .bat files to .exe or .com executable files, or to .VBS scripts, which can be achieved through third-party software such as BAT2EXE, BAT2COM, BAT to EXE Converter, batch encryption converters, and so on. 5. Add the prerequisite commands needed to run subsequent commands in the batch. If we encounter some extreme problems that batch processing and task planning cannot work together, no matter how they are set up in the running environment of task planning, then you can consider adding some prerequisite commands needed to correctly complete the batch command at the front of the original batch content and solve it at the level of the batch itself. For example, the author recently saw a problem in the Microsoft Chinese Forum: a user wrote a batch of backup development code and added it as a task schedule, hoping to run automatically in the early hours of the morning. However, the file backup and copy operations involved in this batch require access to the $IPC network map address. After testing, there is no problem with the batch content written by the user, and if you run the batch manually, you can correctly access the target address and complete the backup, but if you add this batch as a task schedule, the backup and replication operations cannot be performed correctly. It can not be solved by setting the user rights of the task schedule, setting the starting position, converting the format of the batch and so on. The ultimate solution to this problem is to add an item in front of the batch content:

NET USE Z:\\ XXX.XXX.XXX.XXX\ D$ "Password" / User: "Administrator"

Write the prerequisite command for the batch normal access mapping address in front of the contents of the original batch file, and finally the batch file can run normally through task scheduling.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report