With Scheduled Tasks, you can schedule any script, program
or document to run at a time that is most convenient for you. Scheduled Tasks
starts every time that you start Windows XP and runs in the background and it
starts each task that you schedule at the time that you specify when you create
the task (Reference: http://support.microsoft.com/default.aspx?scid=kb;en-us;308569&sd=tech).
The following sample application demonstrates the steps needed
to work with the Windows Scheduled Tasks using a Console application.
Microsoft Visual C# 2005 Express Edition
Create the Console application
Add the new Console Application project (with name as WindowsScheduledTasks)
and paste the following code in it as shown below.
static void Main(stringargs)
StreamWriter sw = null;
sw = File.AppendText("d:/MessageLog.txt");
string ReadString = "This message islogged at " + "DateTime : " +
In the above listing, the program first checks whether MessageLog.txt
exists or not. If it does not exist, it is created.
Next, MessageLog.txt file is opened and a message is logged
into the file using the StreamWriter object. This is done so that when this
console application is added to the Scheduled Tasks, it logs the message into
the MessageLog.txt file at a specified time mentioned in the Scheduled Tasks.
Add the Console application to the scheduled Tasks.
To schedule a new task follow the steps as described below.
Click on Windows Start à
Settings à Control Panel displays
Scheduled Tasks folder in the Control panel as shown in Figure 1.
Double click the Scheduled Tasks folder in the above figure
to open the Add Scheduled Task program as shown in below figure.
Click on Add Scheduled Task in Figure 2, this will run the
Scheduled Task Wizard as shown below.
Clicking on the "Next" button will display a
dialog as shown in Figure 4
Click on the “Browse” button to add the WindowsScheduledTasks.exe
(or some other path where exe file resides) as shown in the above screen and then
To schedule the scheduler component Daily, check the “Daily”
radio button as shown in the above screen and click next. These options should
be chosen as per the User’s requirement.
Designate a Start time and Start Date; the Start Date will be
the current date.
Enter any valid User & Password (with administrative
rights) as shown in the above screen and click on "Next".
Select the Advanced properties option, and click on Finish. The
following screen is displayed.
Click the Advanced button in the above screen, upon which the
below screen is displayed where you can select the Repeat task. With this
setting, scheduler component (WindowsScheduledTasks.exe) will run every two
Verifying the Scheduler Execution
Verify a successful run of the scheduled task by navigating
to D:\ drive and check the MessageLog.txt as shown in the below screen.
In this sample, we have seen that at a specified time
Windows Scheduled Task’s WindowsScheduledTasks.exe component writes a message
into the Messagelog.txt file.
Working with Windows Scheduled Tasks is simple and
straightforward. In this article, we have also seen how we can use Windows
Scheduled Tasks instead of windows Services.
With Scheduled Tasks, you can set up reminders or trigger
e-mails at a specified time. If you explore it, you can find many opportunities
for its usage.