« SharpTerminal Update: Large DPI Gotchas | Main | Innovative--or at least creative--recruiting »

The Windows Task Scheduler Is Not a Second-Class Citizen

R. Frank Lutz has posted a tutorial on scheduled posts using MT3.1 which makes one of those statements that drives me slightly nuts:

Task Scheduler, which comes bundled with Windows attempts to make automation of tasks effortless. Unfortunately, it is not very configurable and basic in what it is capable of. On UNIX and Linux systems, Cron is what is used for task scheduling. This scheduler is very configurable, and is capable of well more then its Windows counterpart.

This isn't actually true. I believe it used to be, though I'm not sure, but for years now the Windows Task Scheduler has been far more capable than most people realize out of the box--it just hides it well.

To set up a task that runs every 15 minutes, here are the steps:

  1. Start->Control Panel->Scheduled Tasks->Add Scheduled Task.
  2. Click Next.
  3. Select any program (we'll be replacing this so it doesn't matter) and hit Next.
  4. Name the task "MT Periodic Tasks".
  5. Select Perform This Task Daily and hit Next. Hit Next (accept the default start time/date).
  6. If prompted, enter your username and password (twice for the password) and hit Next.
  7. Check "Open advanced properties for this task" and hit Finish. The advanced properties will open.
  8. Change the Run: box to read "perl run-periodic-tasks".
  9. Change the Start In: box to the name of the directory where your run-periodic-tasks script is (for example C:\Inetpub\wwwroot\mt\tools).
  10. Select the Schedule tab and click Advanced. Pick today's date as the start date, and check Repeat Task. Set the Every boxes to whatever your repeat rate should be (for instance 15 and minutes). Check the "Duration" button, and set it to 23 hours and 59 minutes and click OK. This will run the task every day and repeat it every 15 minutes for 24 hours. At the end of the 24 hours it will be a new day, and the task will start over -- repeating every 15 minutes for another 24 hours. This part of the interface is especially unintuitive; somebody should make a new interface for Task Scheduler that actually makes sense to normal people. :-P
  11. Change the start time to 15 minutes from now and click OK. If you are prompted again for your username and password, put them in and hit OK.

Your task will now run every 15 minutes until you disable or delete it.


Listed below are links to weblogs that reference The Windows Task Scheduler Is Not a Second-Class Citizen:

» Scheduled Posting using Windows Task Manager from Lutz-R. Frank MT 3.1
new TechBlog();: The Windows Task Scheduler Is Not a Second-Class Citizen Eric posted on his 'new TechBlog()' a highly welcome addition for those who want to stay with the Windows Task Scheduler. Excellent ... even if I seem to have... [Read More]


Lutz-R. Frank said:

;) but does it offer all the options a cronjob can offer - Ok, its a hack but at least it runs

Eric said:

True, running is definitely better than not running. :)

WeatherGuide said:

You can even use it to run a remote job as well.

For example.. take the graphics links you see on this page (under Tropical Storm Jeanne) - http://www.myweatherguide.com/wxguides/hurricanes.aspx - those graphics are actually produced 4 times a day by a scheduled task that goes iexplore [url here]. It has dramatically reduced my server load since Perl/CGI decided to be enrie on my IIS server! :)

JB said:

OK, suppose you're running a large enterprise with dozens or hundreds of servers. You're going to go to each on in turn and run the Task Scheduler to create these tasks? I don't think so. Yet without a way to script the entry of the username and password, for example, under which a Scheduled Task runs, you're absolutely stymied. I'm not sure how you'd perform this basic administrative operation with the Task Scheduler.

Eric said:

Actually, you can create the task once and copy it to any number of other machines. Given that in a large organization like that you'd be using a domain anyway, it's trivial to create the original task, assign a domain user/password to it, and then copy that task wherever it's needed.

AFAIK (and I am not an uber Windows admin) you can actually script tasks using WMI (which means VBScript, .Net, or any of a dozen other scripting tools) as well.

Finally, I don't know if Windows 2003 AD includes a GPO object to create tasks; it might, but I don't know of any.

And if that still isn't enough, you can always fall back on the (very scriptable) AT command...

TimeTraveller said:

Hmm..I just tried copying a task in a Win2003 domain and I get a message saying that it is unable to copy from the source (or something to that effect...I know I know ..ambiguous messages aren't that helpful). I'm wondering if this is likeley to be as a result of the security policies designed by my predecessor or if it's an artifact of SP2...even though I can can easily do this in my XP Home environment with SP2.

Eric said:

I just gave it a try, and it did work for me -- open the Scheduled Tasks folder, right click the task and select Copy. Then browse to the remote machine and open the Scheduled Tasks shared folder (\\machinename\Scheduled Tasks) and paste the task.

You may (probably do) need to have admin rights on the remote machine, and it would not surprise me if there were a GPO or registry key to disable this behavior.

Hope that helps. If you had a specific error message I could do a little more investigation. :)

Mark said:

Check this out- ! its free and done right.


Richard said:

When repeating a task using Windows Task Scheduler, what about the option "Duration" ?
I have to fill in something but the maximum is 9999 hour so that means I have to reschedule my job after a bit more than a year...

Eric said:

Richard, try the following:

Select Run Task Daily, and in the Repeat Task box, select your repeat rate as normal. Set Duration to 23 minutes, 59 seconds.

What this will do is every day it will start repeating the task, every hour, for up to 23 hours and 59 seconds. Then the next day it will start all over again. This will repeat the task at your selected repeat rate indefinitely.

As I somewhat obliquely noted in my original post, the interface for Task Scheduler is really terrible, but the functionality is there. I'll edit the original post to make this point more clear.

Ewan said:

My problem is that you can't script Task Scheduler very easily...At least if you ever change/access the script via the GUI Task Scheduler App. Something to do with the WMI and at.api...See the scripting guys link: www.microsoft.com/technet/scriptcenter/ resources/qanda/sept04/hey0922.mspx

Anybody build a tool for scripting Task Scheduler

Eric said:

In Windows XP you can use the built in schtasks command:
C:\>schtasks /? SCHTASKS /parameter [arguments] Description: Enables an administrator to create, delete, query, change, run an end scheduled tasks on a local or remote system. Replaces AT.exe. Parameter List: /Create Creates a new scheduled task. /Delete Deletes the scheduled task(s). /Query Displays all scheduled tasks. /Change Changes the properties of scheduled task. /Run Runs the scheduled task immediately. /End Stops the currently running scheduled task. /? Displays this help/usage. Examples: SCHTASKS SCHTASKS /? SCHTASKS /Run /? SCHTASKS /End /? SCHTASKS /Create /? SCHTASKS /Delete /? SCHTASKS /Query /? SCHTASKS /Change /?

Sohcool said:

I hope it is appropriate to ask a question here.

I have a program to import files on a daily basis. These files are named starting with the date of day they are to be imported. I wonder how I can set the Windows Scheduler to take in the file dynamically by the date.
eg: 07022005import.xml
08022005import.xml etc...
I do not want to go into Windows Scheduler each time to change the file name. So it is limiting to use WS.

Any advise out there?


Eric said:

Sure Ashley, no problem. What you would want to do is use a batch file to insert today's date, and then schedule the batch file. That file would look something like this (save it as importfile.cmd):
rem importfile.cmd rem get today's date set Day=%Date:~7,2% set Mth=%Date:~4,2% set Yr=%Date:~10,4% rem handle single-digit days set Day1 = %Day% if %Day% LSS 10 set Day1=%Date:~8,1% set Mth1 = %Mth% if %Mth% LSS 10 set Mth1=%Date:~5,1% importfile.exe %Mth%%Day%%Yr%import.xml

Note that depending on your system, the output of the Date command may be differently formatted, and you would need to change the substring arguments accordingly.

Roland said:

Now there is only real problem left. If I schedules a command on a remote computer that actually runs a batch job, there is not way to set the "start in" folder for the job. Not even with SCHTASKS. The second and third line in my batch file is
cd d:\backups\
to allow control to be where the batch file actually resides, but it doesn't work. The commands don't run.
How do I get past that?

Dana said:

I stumbled across this site while looking for some help and hope somebody can help me with a long term problem.

I run queries in Excel which access our AS400. I would like to set up a task or macro which will run the query on a pre-defined time (like the 15th of every month), create a new spreadsheet with this information and save in a certain folder. Does anybody have any advice?

Thanks so much for any help you can provide

Eric Author Profile Page said:

Roland, a couple of thoughts:

1. You could prepend the d:\backups\ to all the commands that need it. For instance, if your batch file were

d: cd d:\backups\ del oldbackup.dat ren currentbackup.dat oldbackup.dat ...

then you could change it to
del d:\backups\oldbackup.dat ren d:\backups\currentbackup.dat oldbackup.dat ...


The other possibility is that the task is running as a user that doesn't have permission to access (or possibly just to write to) the d:\backups\folder. I would check who the task is running as (in the task properties) and check the permissions on that folder.

Eric Author Profile Page said:


What you want to do is a job for a script or program. You could use either WSH (Windows Scripting) or some programming language (VB, for instance) to write a program that does what you want. There is an example of using WSH with Excel here that should get you started. You may need some more resources in order to figure out how to pull the data from your AS/400; if you can't find anything on Google, let me know and I'll see what I can dig up.

Once you have a script, call it createexcel.vbs, you would schedule that script according to my original post.

ezis2a said:

Unfortunately, i just found that SCHTASKS.exe does not support seconds!

For some strange reason, it has start time parameter, outlined in help like it would have seconds - /ST 23:59:59, but in reality, the task is set to 23:59, skipping the seconds.

How it can be like this? ... crap of shit..

Or am i missed something?

Eric Author Profile Page said:

Not sure what's going on there. According to this MSKB article, it certainly seems as if SCHTASKS ought to support seconds, but testing on my own PC didn't work either.

Gayathiri said:

I have to schedule a task using "schtasks".
The task which i have to schedule takes 1 or more command line parameters.
Where should i bring in the parameters in the schtasks command.
Are there any solutions


haklan said:

Hi everybody,

I'm looking forward to be using this Task schedule "Cron" function in a webapplication I wrote.

I've got an url witch I want to call at a certain time of day. and after execution this url close the explorer window. Or else the server open's up a explorer window everyday.

Can anyone help me out?

Eric said:

Gayathiri, try putting the entire command line in the schtasks command like so:
C:\>schtasks /Create /SC DAILY /TN MyTask /TR "C:\WINDOWS\notepad.exe C:\myfile.txt"
This would launch notepad and tell it to open C:\myfile.txt.

haklan, I would try googling for an app that can automatically close a window based on the app name or window title. I believe there's one called pskill that will take a process name; you could stick the following in a .cmd file and process that. I would stick a "sleep" utility (which basically just pauses for a number of seconds; you should be able to google for this too) between them to let the web page load:
REM launchExplorer.cmd start http://www.example.com/ sleep 10 pskill iexplore.exe
Potential problems include that if the user has Internet Explorer open, it may close that too. It also doesn't cover the situation where the default browser is not IE (for instance, if it's Firefox).

Ken said:
The sleep utility is, thankfully, no longer required. I saw the following trick on a forum several months back. To speed for "X-1" seconds, do:

ping -n X

So to sleep for 10 seconds, do:

ping -n 11

Ping pauses a second between attempts, and pinging localhost is basically a no-op, so this is a cool trick to get around the lack of a sleep.exe program on any system you're working on.



Eric said:
I also have been trying to figure out the dynamic date thing that Ashley was talking about, and I don't think that I really comphrehend the response given.

I am attempting to have a scheduled task that runs windows media player encoder daily, and just pulls the file for that day from the day's folder (i.e. c:\04012005\file.wme).

This is the command I'm already using:

   "C:\Program Files\Windows Media Player Utilities\Encoder\wmenc.exe" -open "C:\Today's Media\file1.wme" -start

I want to replace the "Today's Media" file with the individual date so that I can start archiving the media files by not replacing the folders.



Eric said:

Eric, try this. Copy the lines below, and paste them into Notepad. Save the new file as C:\encode.cmd
rem get today's date set Day=%Date:~7,2% set Mth=%Date:~4,2% set Yr=%Date:~10,4% rem handle single-digit days set Day1 = %Day% if %Day% LSS 10 set Day1=%Date:~8,1% set Mth1 = %Mth% if %Mth% LSS 10 set Mth1=%Date:~5,1% "C:\Program Files\Windows Media Player Utilities\Encoder\wmenc.exe" -open "C:\%Mth%%Day%%Yr%\file1.wme" -start

Then, instead of scheduling wmenc.exe, schedule the encode.cmd file. This is a special file called a "batch file", which is basically just a series of commands to Windows. Inside the batch file, each line is a command. The first several lines deal with getting today's date into three variables, Mth, Day, and Yr (anything after a "set" command, or surrounded by % signs, is a variable). The last line uses the values of those variables to execute the command in the correct directory. The last line will end up being executed as
?C:\Program Files\Windows Media Player Utilities\Encoder\wmenc.exe? -open ?C:\04012005\file1.wme? -start
(if executed today).

If that doesn't help, please post back with more questions.

Stan said:

This chain has been helpful, but I can't get scheduler to run my .bat or .cmd files. All it does at the scheduled time is flashes open the cmd window and it immediately shuts down.

Any thoughts on how to get a .bat file to run?

I use the file to create a backup of specific directories to an external harddrive...

Eric Author Profile Page said:

Hey Mason, the batch file may be encountering an error that causes it to close. You could try putting the following line as the last line in your batch file:


That will pause the command window before it closes, so that you can see if there is an error or not.

If the window still flashes, then it?s not even getting to run your batch file; in that case, check and make sure that the path and filename are right, and that you have put quotes around the path to the batch file if it has spaces in it.

Raj said:

I am seeing in the scheduled tasks 'could not start'. How do I trouble shoot?

Scott said:

I hope someone sees this post as I'm dangling at the end of my rope on this one! I need to kick off a job immediately after my Oracle tables have been updated. Our crappy Oracle scheduler (Tivoli) doesn't have the ability to do a "run as" and I need to run my jobs with a specific user ID. I can't just schedule the job to run in Windows Scheduler because it needs to run at different times each day. Anyone have any advice at all??

Eric said:

Scott, sorry this is so late, but if you are running Windows XP or 2003 on the machine in question, I would advise you to look at the schtasks command, which should allow you to script jobs much more fully.

Specifically, it will allow you to create a job (just set the schedule to Once), execute it, and then delete it. Alternately you could create the task once, and then just do a /RUN whenever you needed it to run (possibly preceded by a /CHANGE if you needed to change a parameter).

Hope that helps.

mrd said:

There is a program called VisualCron which is an advanced scheduler for Windows. You can also use it to ping/POST to external sites at random intervals. http://www.visualcron.com

Chuck said:

Is it possible to scedule a program to close with windows task scedule?

Eric said:


It's quite possible. The safest/easiest way to do it is probably to use the taskkill tool as your scheduled task, assuming you're using Windows XP; you will probably want to feed it an imagename (the name of the EXE file) as the PID won't be predictable.

Becky said:

I want to do what seems to be a very simple thing. Every Friday afternoon I want to bring up an IE browser and go to the URL where I can enter my time card info. I can see how to bring up the browser, but how do I make it go to the URL? (Without setting it as the home page). I have the feeling this is probably an extension on the run statement, but am at a loss about what it would look like.

Eric Author Profile Page said:

Becky, that should indeed be a simple thing; all you need to do is put the following in the Run box:

"C:\Program Files\Internet Explorer\iexplore.exe" [URL here]

That will start Internet Explorer and point it at the URL you put in (replace the [URL here]).

Fred said:

A good scripting language for Windows is WinBatch, from:


It has tons of extensions so that you can script Windows to, say, talk to lab equipment or work with Active Directory services.

Donald said:

Trying to create scheduled tasks from within a batch file using schtasks. Unfortunately the quotes for my path are not being carried into the created tasks and are needed for the path. Ex. "C:\Program Files\..." Therefore if my batch file has schtasks /create /tn "DeleteFiles" /tr "C:\Program Files\Test\DelFiles.bat" /sc daily /st 03:05:00 /ru "" it will create the task with the path C:\Program Files\Test\DelFiles.bat and not "C:\Program Files\Test\DelFiles.bat". So the task will not run because the path is invalid without the quotes. Short of using 8.3 names is there a way to fix this?

Donald said:

Never mind. Got it. FYI.. use \ "


Thanks again,

CronUser said:

I just wanted to comment that at least cron works, and if it doesn't then there will be a paper trail to follow and find out why. If a windows scheduled task does not run, you are SOL. You will see some kind of error number, but this number will not be documented anywhere. When using cron, the problem is rarely (i.e. 'never in my lifetime') a problem with cron itself, but instead the script cron is running.

Rick said:

To use quotes in the schtasks command line, you have to use the \ as an esc character. Checkout the following whitepaper for more details:



Oz said:

Hi, I'm trying to set a scheduled task to visit a webpage at 3 in the morning, for the duration of an hour and keep refreshing the page.

My Question is, how?
I'm totally clueless when it comes to programing. Please help!

Dipak said:

I hope it is appropriate to ask a question here.
I have a program to run file on a daily basis. These file are name bhajan.wpl (it’s media player list ). I want to how I can set the Windows Scheduler to take in the file daily 8:00AM start
It’s run but it I close the media player everyday !!!
I do not want to go into Windows Scheduler each time to change the file name. So it is limiting to use WS.
Any advise out there?

Eric Author Profile Page said:

Dipak, try using something like what I suggested for this comment above. That would let you execute it using today's date rather than a hardcoded file name.

Jody said:

I've got a scheduled task to run an Access macro nightly, as another user. To test it, I logged in as that user and ran the task "live" - I found that I needed to change the sandbox mode settings, and it ran fine. However, when I check the task status in the morning, it's "Running." Is this possibly because the sandbox mode settings are user-specific? Can I make them computer-specific?

samir namjoshi said:


I want a list of all the schedule tasks under my schduler in Excel or atleast in text document. Does anyone know how do you get this? Server is Win2000 so SCHTASKS does not work here. Please let me know


Maybe this is a stupid question, but where can I find a "run-periodic-tasks" script
so that this script will visit a web page!

Ishan Jha said:

Hi all

Just wanted to know whether time of scheduled tasks can be changed on "n" number of remote servers using scripts.For Instance say if i want to change backup time of 5 serevers. Is it possible using script ???


Leave a comment


This page contains a single entry from the blog posted on September 15, 2004 12:05 PM.

The previous post in this blog was SharpTerminal Update: Large DPI Gotchas.

The next post in this blog is Innovative--or at least creative--recruiting.

Many more can be found on the main index page or by looking through the archives.

Creative Commons License
This weblog is licensed under a Creative Commons License.