title: How do I get Task Scheduler Last Run Result exit code for batch script?
body: <p>I need to know if the task ran successfully so I can create an event in the Application log saying so. Is there a way to get this in code? I tried the following:</p>
  
  <pre><code>echo ErrorLevel of "c:\windows\system32\tasks\my task" = %ErrorLevel%
  </code></pre>
  
  <p>But I get 0 every time, even if I stop it prematurely (0x41306) or while the task is still running (should be 0x41301). Does anyone have any ideas? Thank you.</p>
  
  <p>I found a workaround to this. Instead of getting the exit code of the task, I got the exit code of the batch script that actually runs and if it's anything but 0 then I make an error application event, otherwise it's a success application event.</p>