Thursday 3 May 2018

windows - How do you schedule a task (using schtasks.exe) to run once and delete itself?

I want to schedule a task from the command prompt (using schtasks.exe) to run once and delete the task entry from the Task Scheduler Library after completion.


After looking through the usage guide, I settled on this command:



schtasks /create /TN SomeTaskName /TR "notepad.exe" /SC ONCE /ST 12:00 /Z

...but that gives me this error (I'm running Windows 10)



ERROR: The task XML is missing a required element or attribute.
(40,4):EndBoundary:

Looking it up online, I found out about this KB article that suggests using the /V1 switch to get rid of the error but on adding /V1 I am asked for the current user password to schedule the task. I don't want that.


Is there any way to schedule a task to be executed once and then deleted from the task library after execution completes?


I've tried this, but it didn't work:



schtasks /create /TN SomeTaskName /TR "schtasks /delete /TN SomeTaskName /F" /SC ONCE /ST 12:00

A kludgy solution I came up with that works is this:



schtasks /create /TN SomeTaskName /TR "notepad.exe" /SC MINUTE /MO 1 /ST 12:00 /ET 12:02 /Z

It has the side-effect of performing the task thrice before stopping.

No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...