Quantcast
Channel: Active questions tagged windows - Super User
Viewing all articles
Browse latest Browse all 8889

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

$
0
0

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.


Viewing all articles
Browse latest Browse all 8889

Trending Articles