Configuring cron jobs on Windows
To setup a Windows machine to run cron.php at a specific time follow the specific instructions below. This can be useful if you are not familiar with Linux/Unix, or if your web host does not offer the ability to run cron jobs; you can run them remotely from your own computer.
Note: These instructions were written for Windows XP but should be similar in other versions of Windows.
Creating a Scheduled Task
- Open Scheduler
- Go to Start > Programs > Accessories > System Tools > Scheduled Tasks
- Double-click Add Scheduled Task
- The Scheduled Task Wizard will appear. Click Next.
- Select the program to run. Choose your browser from the list (for example, Internet Explorer or Mozilla Firefox). Click Next.
- Give the task a Name, such as Drupal Cron Job, and choose the Frequency with which to perform the task (for example, Daily)). Click Next.
- Choose specific date and time options (this step will vary, depending on the option selected in the previous step). When finished, click Next.
- Enter your password if prompted. Change the username if required (for example, you'd like the task to run under a user with fewer privileges security reasons). Click Next.
- On the final page, select the checkbox Open advanced properties for this task when I click Finish and click Finish.
Configuring the task
- Go to the task's setting page either by checking the checkbox at the end of the last step, or by double-clicking on the task.
- In the Run box, after the text that is there now (for example, C:\PROGRA~1\MOZILL~1\firefox.exe), enter a space and then type the address to your website's cron.php page in double quotations (for example, C:\PROGRA~1\MOZILL~1\firefox.exe http://www.example.com/cron.php
- To set a frequency more often than Daily (for example, hourly), click the Schedule tab, then click Advanced. Here you can set options such as Repeat task, every 1 hour for 23 hours. Click Ok when finished.
- Change the start time on the task to one minute from the current time. This will allow you to test the task and make sure that it is working.
- When all settings have been configured to your liking, click Apply and OK (note: you may be prompted for your password)
Command-line version
Another way to perform the above commands is by using the schtasks (or at in Windows 2000) command from the command line. To duplicate the example above, which runs Firefox hourly to execute http://www.example.com/cron.php, open a command prompt (Start > Programs > Accessories > Command Prompt) and enter:
schtasks /create /tn "Drupal Cron Job" /tr "C:\PROGRA~1\MOZILL~1\firefox.exe http://www.example.com/cron.php" /sc hourly
Enter your password if prompted.

Forward Slashes
Scheduled Tasks converts the forward slashes of the URL into back slashes if they're placed in the double quotes (at least in Windows Server 2003). The URL needs to be placed outside the quotes:
"C:\PROGRA~1\MOZILL~1\firefox.exe" http://www.example.com/cron.php
Using 3rd party tools
There are several cron implementations available for Windows. I've used nnCron ( http://www.nncron.ru/ ) with great results. The Lite edition is free and runs as a service.
wget is also available for Windows, at http://gnuwin32.sourceforge.net/packages/wget.htm
How To: Auto Close Browser after Cron Run
This is the setup I use and it works very well. I use a slower computer for my server and every bit of resources I can keep free is important. So when I use the above method it keeps the browser window open and I'd prefer it didn't. I created a second scheduled event that closes the browser window. There are two ways of doing it if you have XP Pro but only one with XP home. The way that will work with both is as follows...
Now XP Pro ONLY
now you can set the event one minute after you have cron run and it will close the window too.
The Pro only way is a better more powerfull version of the tskill found in XP Home but for the propose of this use either should work just fine.
NOTE: Does not work with Firefox because of Firefox's attempt to restore sessions after being killed
Firefox and IE replacement
Use wget Win32 port (you can find it on http://users.ugent.be/~bpuype/wget/ or look for "wget win32 download" in Google)
small command line utility.
So command line for Scheduled task will be
wget.exe -q -O nul http://drupal/cron.phpYou can add full path before wget.exe and surround it with quotes if need.
wget did the trick
thanks for the wget tip. It works great.
Have the job close the application.
Instead of "killing" the task, you can also set up the original task to stop it. On the Setting tab, check the Stop the task if it runs for: 0 hour(s) xx minute(s). I would suggest letting it run for at least 10 minutes, depending on how many tasks it has to perform and how long it runs.
I run a five different non-commercial Drupal sites on my server and I have a job for each every half hour and closing after 15 minutes. You can imagine how many browser windows it would leave open after a week. Sometimes I don't check the console for a month..
Closing App - Use IE on a Windows Server
I've been playing around with Cron a lot on a Windows/Apache server and found that Firefox (v3) wouldn't shut down after a Cron run, and wouldn't open another instance of Firefox an hour later... so tried IE7 which seems to work fine. Not sure why - but I'm just going to leave it ticking away
thanks, good idea
thanks, good idea
cron in xp home syntax
be careful as this is very tricky...
seems that on my box the line to successfully run cron in Firefox is
"C:\Program Files\Mozilla Firefox\firefox.exe" "localhost\cron.php"
Obviously mine is a local server and you need to change localhost to whatever your own domain might be....
I posted this as in the page above I got a tad confused as I didnt see the part about the quotes! Xp
Cheers
Nate
That worked
Brilliant. Thanks Nate.
Cron jobs in Windows using JavaScript
To avoid using browsers to open the cron.php page (or any other HTTP page) you must create a small script in JavaScript (formally JScript) and run it as a Windows scheduler job as explained in this article. The script use the COM WinHttp object, so perhaps it works only if you have installed Internet Explorer 7 (not tested with previous versions).
function HTTPRequest (sURL)
{
var sResult = "";
try
{
// Create the WinHTTPRequest ActiveX Object.
var oWinHttpReq = new ActiveXObject ("WinHttp.WinHttpRequest.5.1");
// Create an HTTP request.
var oTemp = oWinHttpReq.Open ("GET", sURL, false);
// Send the HTTP request.
oWinHttpReq.Send ();
}
catch (oError)
{
sResult = "WinHTTP returned error: " +
(oError.number & 0xFFFF).toString () + "\n" +
oError.description;
}
// Return the response text.
return sResult;
}
// Main
var sURL = "http://www.mysite.local/cron.php";
var sError = HTTPRequest (sURL);
if (sError != "")
WScript.echo ("Error on URL: " + sURL + "\n\n" + sError);
If you have more than one site to update you can put them all in the same script
// Main
var sError, s;
var sURL = "http://www.site_one.local/cron.php";
s = HTTPRequest (sURL);
if (s != "")
sError += "Error on URL: " + sURL + "\n" + s + "\n\n";
sURL = "http://www.site_two.local/cron.php";
s = HTTPRequest (sURL);
if (s != "")
sError += "Error on URL: " + sURL + "\n" + s + "\n\n";
...
...
...
if (sError != "")
WScript.echo (sError);
that's all folks
Cron Task in Vista
This set up will leave the browser open, at least for 30 min. You have to do one for each site. On the good side it's easy and works.
For Vista go to task scheduler and 'Create Task'.
In the dialog window use these tabs...
set up schedules time(s)
--advanced settings: stop if runs > 30min
Program/script:
"C:\Program Files\Internet Explorer\iexplore.exe"Add args:
http://example.com/cron.php(don't use quotes)Cron using Wget for Windows and Scheduled Tasks
Here's how I solved this under XP Pro. I grabbed Wget for Windows from http://gnuwin32.sourceforge.net/packages/wget.htm . For those who don't know, wget is a 'nix command line file fetcher that uses either the http or ftp protocol. The file specified on the command line is written to a local file, rather than being displayed in a browser.
I recommend you get "Complete Package (except sources)." This will get you the documentation, which is handy, along with the binary. It is packaged as an ms executable. I ran it and accept the default destination (C:\Program Files\GnuWin32\bin).
Once I did this, I went to "My Computer" in the Start menu and right clicked on it, then selected "Properties." On the "Advanced" tab, I clicked the "Environment Variables" button.
In the "System Variables" window at the bottom of the window, I scrolled down to find the "Path" variable and clicked on it to highlight it, and then clicked the "Edit" button. I went to the "Variable Value" input box and went to the end of it. I then added the following to the end of the string, being careful not to delete anything that was already in there -- note the semicolons, they're important:
;C:\Program Files\GnuWin32\bin;Then I opened a dos console (Start button, "Run...", then type "cmd" in the "Open:" input box) and input the following command from whereever the console opened up (it doesn't matter):
wget -O nul http://localhost/cron.phpThe -O is "dash capital O", not "dash zero". Yes, the capital O is important. Lowercase o won't work.
A moderate amount of output ensued into the console window, ending with the notation that file nul had been created. Actually, nul is the MS-DOS equivalent of /dev/null, so what had really happened is that the output had been swallowed. I checked the Drupal recent events log and determined that the cron job had indeed run successfully.
Next, I wrote an MS-DOS batch file, so that I wouldn't be bothered with passing parameters through Scheduled Tasks:
@echo off
rem
rem wgetCronPhp.bat
rem
rem Fetches cron.php from the localhost root and writes it to the nul device.
rem
wget -O nul http://localhost/cron.php
I stored the file in a utilities folder on my hard drive, and double clicked on the batch file to run it. I was satisfied to see that the output was as before, in the manual test. The only problem was that the ugly black console window popped up. I decided to suppress it. I right-clicked on the batch file and selected "Properties", and noticed that there was no way to have the program run minimized.
I then closed the Properties window and right-clicked on the batch file again. This time I selected "Send To > Desktop (create shortcut)".
I went to the desktop and double-clicked on the shortcut. The results were the same as double-clicking on the batch file itself. Same output, same ugly black box.
I then right-clicked on the shortcut. I again selected the "Properties" item, and was gratified to see that several more tabs were available here on the Shortcut.
I selected the "Shortcut" tab from the Properties window and located the "Run" pulldown box. I selected "Minimized" from this pulldown and OK'd out. I again ran the shortcut file, this time while looking at the Windows taskbar. The batch file icon came up in the taskbar for several seconds, and then disappeared. Beautiful.
I then moved the shortcut to the directory above my web root, and proceeded to enter it into Scheduled Tasks as outlined in the main article. Now cron runs regularly, and I'm not bothered by anything popping up on the screen.