December 24, 2009

How to configure cron job in windows

cron job can make your life easier than you ever thought. even though, cron job is not much popular in most web hosting that running windows as their platform. Most people that have a script to automate their website (i.e backup) tend to choose web hosting that run in Linux because setting up cron in Linux is far more easier than in windows.

This tutorial is based on Windows XP SP2 build 2.6. But, the step should be the same with all windows version

open Scheduled Task.

start > Accessories > System Tools > Scheduled Tasks

You should now have this nice windows appear on the screen.

double click on Add Scheduled Task

Press Next.

Choose your favourite Browser. In this tutorial, i choose Mozilla firefox.

Press Next when you done.

Now, put the name of cron Job. Here, you can see that i put Cron Tutorial, and of course you can put whatever you like.

In This step also, you must choose the time when Windows executed the cron job. Here i choose Daily

Press Next when you satisfied.

Choose the time for the cron job to start. By default, current time will be shown in the input boxes.

the next option is to tell the scheduler to run your cron job.

The dropdown boxes is to tell the scheduler when to start your cron job. By default, current date will be shown.

Press Next when you done.

This screen is the tricky part. If you only have ONE user in your computer, it is advisable to create one more user with any privilages (i.e any privilages can be use Admin or Limited) plus you MUST provide a password for the newly created user.

If do not wish to create another user, and your current user already password enable then you can use your current user in the next screen.

If your current user do not have password, then you must create password for it or you can choose to create another user with password enable.

Press Next when you done.

On the next screen, before you press Finish make sure you check the check box that say "Open advanced task when i click finish"

Now We finish setting up the cron job. Next step is to tweak your cron job a little bit.


This will be on your screen right now.

To make sure that your cron job running correctly, you must provide the full path of your script. in this example, our script will be located in this location;


Please see the path carefully. Normal path in windows will be like this:


on the above screen, put the full path to your script next to C:\PROGRA~1\MOZILL~1\firefox.exe

so, the screen will look like this:

the value in Run textboxes will be like this:

C:\PROGRA~1\MOZILL~1\firefox.exe D:/xampp/htdocs/path/to/cron/script.php

there is a space in between C:\PROGRA~1\MOZILL~1\firefox.exe and D:/xampp/htdocs/path/to/cron/script.php

Next, go to Schedule tab and click the Advanced button.
Here will be the screen that you should see.

when you click advanced

check the check box next to Repeat task and fill the content to your like.
here is my setting(i.e you may tweak it to suit your need)

My reason:
1 : i want the cron job to run every 1 hour
2 : the cron job will run for 23 hours a day continuously
3 : the cron job will be terminated if it still running when the time to run the cron job come again.

to check whether your cron job is running as you wanted, you can change the time by double-clicking your cron job and go to scheduled tab. Alter the run time to past 5 minute or less with your current time.

After that, you can read some other article in this blog while waiting for that 5 minutes. hee~~

When the time come, you might expect your browser to pop-up and start executing your script. Well, you are wrong!! You will not see the browser to pop-up as you expected because it will run in the background silently.

you can open Task Manger to see if it working or not. Press CTRL+ALT+DEL simultaneously to bring your Task Manager.

Go to Processes tab and look for firefox. p/s: please close your browser (firefox) before hand.

UserXP : My current log-on user
cron : Username for the cron job

No comments:

Post a Comment

Whats your thought on this post?