[英]Batch file to create a trigger to start a task
I have created two task Task1 and Task2 through a .bat file using the command schtasks.exe. 我已经使用命令schtasks.exe通过.bat文件创建了两个任务Task1和Task2。
I need to create a trigger that will trigger the start of Task2 when Task1 is completed. 我需要创建一个触发器,当Task1完成时将触发Task2的启动。
Where and how do I write the commands for the trigger in the batch file? 我在哪里以及如何在批处理文件中编写触发器的命令?
If I create the trigger manually in the Windows Task Scheduler then following is the XML I use in the Trigger tab of Task2. 如果我在Windows Task Scheduler中手动创建触发器,则以下是在Task2的“触发器”选项卡中使用的XML。
<QueryList>
<Query Id="0" Path="Microsoft-Windows-TaskScheduler/Operational">
<Select Path="Microsoft-Windows-TaskScheduler/Operational">*[EventData[@Name='TaskSuccessEvent'][Data[@Name='TaskName']='\Task1']]</Select>
</Query>
</QueryList>
Here is the content of the batch file: 这是批处理文件的内容:
@echo off
Set RUN_AS_ACCT=%USERDOMAIN%\%USERNAME%
echo The currently logged on user is: %RUN_AS_ACCT%
echo.
set /P INP_RUN_AS_ACCT="Account to run the batch under?(%RUN_AS_ACCT%) "
IF NOT "%INP_RUN_AS_ACCT%"=="" SET RUN_AS_ACCT=%INP_RUN_AS_ACCT%
echo.
echo Using: %RUN_AS_ACCT%
schtasks.exe /CREATE /RU "%RUN_AS_ACCT%" /RP /TN "Task1" /tr "D:\load\Task1.bat"
echo.
schtasks.exe /CREATE /RU "%RUN_AS_ACCT%" /RP /TN "Task2" /tr "D:\load\Task2.bat"
echo.
pause
:EOF
You could create a schedule to run the following: 您可以创建时间表以运行以下命令:
cmd /c start /wait task1.exe && start task2.exe
When task1.exe
closes, task2
will automatically start. 当task1.exe
关闭时, task2
将自动启动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.