title: Batch file to create a trigger to start a task
body: <p>I have created two task Task1 and Task2 through a .bat file using the command schtasks.exe.</p>
  
  <p>I need to create a trigger that will trigger the start of Task2 when Task1 is completed. </p>
  
  <p>Where and how do I write the commands for the trigger in the batch file?</p>
  
  <p>If I create the trigger manually in the Windows Task Scheduler then following is the XML I use in the Trigger tab of Task2.</p>
  
  <pre><code>&lt;QueryList&gt;
    &lt;Query Id="0" Path="Microsoft-Windows-TaskScheduler/Operational"&gt;
      &lt;Select Path="Microsoft-Windows-TaskScheduler/Operational"&gt;*[EventData[@Name='TaskSuccessEvent'][Data[@Name='TaskName']='\Task1']]&lt;/Select&gt;
    &lt;/Query&gt;
  &lt;/QueryList&gt;
  </code></pre>
  
  <p>Here is the content of the batch file:</p>
  
  <pre><code>@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
  </code></pre>