How to run a task triggered by an event only once
You might want to start or stop a task when a particular event is logged. For instance start a service or stop tracing. You can use the the Attach a Task To the Log option in the Event Viewer
The Attach a Task if found here
For example
Therefore you can create a simple batch file like this:
net stop spooler
pause
And add the batch here
After you have finished the wizard, you will find in the task scheduler the following task
You can here change the task here to your own needs, in this example I add event 222 as trigger
Now if event 222 is logged in the application log, the printer spooler is stopped
But now, if you want to run this only once, only the first 222 event and not the ones coming after? Simply add the following line to your batch file
net stop spooler
schtasks /Change /TN "\Event Viewer Tasks\Stop Printer Spooler" /DISABLE
pause
This will disable the task
Which you can see here
Hope this is helpful!
Credits for Dirk van Coeverden and Nicolas Uthurriague