Implement import with DOS command, export Windows Plan task detailed _dos/bat

Source: Internet
Author: User
Tags schtasks

Beginner's Guide
to import a new system using a command-line batch of scheduled tasks for company software, all by looking up data, a script that can be used to export and import.
The export usage is: script name + Space +export
The import usage is: script name + Space +import

The following are content and comments:

REM The following is printed @echo off REM for the shutdown command the following for the clearing screen CLS-REM The following for setting this batch all environment variables apply only to the current batch setlocal enabledelayedexpansion REM The following for setting variable set RU Nasusername=domain\administrator set Runaspassword=password REM The following%1 is the first command-line argument after the execution of this batch (in the format executed: script name +export is equivalent to jumping to " : Export ") if%1. = = Export. Call:export if%1. = = Import. Call:import REM Following for exiting the current script, not exiting the entire batch exit/b 0:export REM below for creating a Tasks folder, all errors do not show MD tasks 2>nul REM below for listing all scheduled tasks and refer to In CSV format, and then find the line that does not match the string taskname, output to a text file schtasks/query/fo CSV | findstr/v/C: "TaskName" > Tnlist.txt rem Loop find each item of each row with (,) as the delimiter, specify%%i as the first item, specify the second tokens=1,2 and the third item%%j with%%k (also rem specify percent% T is the first item, then tokens=1,2 specifies the second%%u and the third item%%v, the fourth item is%%w) for/f "delims=, tokens=1,2*"%%i in (tnlist.txt) do (Echo%%i echo%%j EC
 Ho%%k set tn=%%i rem below for setting FN to replace the contents of TN with the # set fn=!tn:\=#!
 Echo!tn!
Echo!fn! REM The following is a xxx.xml file that lists all scheduled tasks and specifies the XML format to be exported to the Tasks folder in the current directory schtasks/query/xml/tn!tn! > tasks\!fn!. XML) REM Delete all Windows self-contained scheduled Tasks del tasks\ #Microsoft *.xml exit/b 0 REM The following is the import label, in the format executed: script name +impoRT will jump right here to start execution: import REM loops through this directory to find all XML for%%f in (Tasks\*.xml) does (REM uses the call command to invoke (: importfile) tag execution, and gives the above lookup     
The name is the parameter Call:importfile "%%f") exit/b 0:importfile REM The following is the first argument given when the call command is set filename= above, and the second argument if it is set filename=%2 Set filename=%1 REM The following is set to replace the # character in filename with empty set taskname=%filename:#=% REM to replace the tasks\ character in filename with an empty set taskname=
%taskname:tasks\=% REM The following for setting the filename in. Replace the XML character with an empty set taskname=%taskname:.xml=% REM The following is the plan for creating a name for XXX with username and password, which is considered as an XML file as a parameter Schtasks/create/ru%runasusername%/rp%runaspassword%/tn%taskname%/xml%filename% echo on

ends
so that you can export all scheduled tasks that are not the system's own and import the existing XML format's scheduled tasks

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.