Using schtasks.exe, how do I create a Scheduled Task, then delete it afterwards?

Viewed 307

I have a .bat file which needs to schedule a command at 5:00 PM.

I cannot use Task Scheduler, because at the end of the file I need to delete the scheduled command (cancel it), without having to manually confirm the delete!

I need an alternative to the at command, since its deprecated.

Right now I'm doing it like this, but it needs user input when deleting it!

SCHTASKS /CREATE /SC DAILY /TN "Custom\Abort shutdown task" /TR "%windir%\System32\shutdown.exe /a" /ST 17:00:30
SCHTASKS /delete /TN "Custom\Abort shutdown task"
1 Answers

Check schtasks.exe /CREATE /? for this:

/Z          Marks the task for deletion after its final run.

In top of that, there's the /SC switch, giving you the possibility to launch the task only once.

The combination might be what you are looking for.

Related