I have created two task Task1 and Task2 through a .bat file using the command schtasks.exe.
I need to create a trigger that will trigger the start of Task2 when Task1 is completed.
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.
<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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.