Setting up a task schedule with batch code

0

Is there a way to set up a task schedule, as in "Windows Task Scheduler", using batch files?

Daniel

Posted 2016-10-21T20:17:13.980

Reputation: 283

Can you clarify what you have tried and what exactly you are trying to do? – Burgi – 2016-10-21T22:08:02.207

I don't know how to better state it. I would like to use batch files to set up a few tasks on Task Scheduler. – Daniel – 2016-10-21T22:31:50.403

Answers

2

Look at schtasks.exe /?

For example, to create a task that starts notepad five minutes after you log on, you can do this (only as an administrator, unfortunately):

schtasks /create /tn "\Automatic Notepad" /sc onlogon /delay 0005:00 /ru YOU /it /tr notepad.exe

Replace "YOU", of course. There is one problem: This will start the program when any user logs on, as long as you are also logged on. schtasks does not appear to have an option to set the target user of a logon trigger.

However, if you only need to create tasks that run periodically, or that should run even when a user is not logged on, this may not affect you. You could also (although this is getting slightly past the capabilities of batch files) create the task definition in XML and create the task from that (schtasks /create /xml), or create the task using the "normal" arguments, then export it (schtasks /query /tn ... /xml one), insert the required line and reimport the task.

Christian

Posted 2016-10-21T20:17:13.980

Reputation: 126