简体   繁体   English

批处理文件以创建启动任务的触发器

[英]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.

相关问题 Windows 任务计划程序不启动批处理文件任务 - Windows Task Scheduler doesn't start batch file task 如何使用批处理文件设置Task Scheduler Start in(可选)属性 - How to set task scheduler Start in(Optional) property using Batch file 使用任务计划程序运行包含start / w命令的批处理文件 - Using Task Scheduler to run a batch file that contains the start /w command 在任务计划程序中运行批处理文件时无法创建日志文件 - cannot create log file when running batch file in task scheduler iMacros-创建批处理文件以在现有浏览器窗口中启动javascript文件 - iMacros - create batch file to start javascript file in existing browser window SQL触发批处理文件 - SQL to trigger batch file 批处理文件和任务计划 - Batch file and task schedule 如何在 Windows 中创建批处理文件来修复和启动损坏的 mongoDB? - How to create a batch file to repair and start corrupted mongoDB in windows? 如何使用带有空格的路径和命令的“start”在Windows中创建批处理文件 - How to create batch file in Windows using “start” with a path and command with spaces 使用批处理文件创建并启动Windows 7或10服务? - Create and start Windows 7 or 10 service using batch file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM