Even though I've heard the virtues, I've never been good at keeping my hard drives defragged and healthy. If I can't set it to run regularly like my good ol' anti-virus scan, I'm not interested. And yet, there's no way I'm actually going to buy software that will do this for me (heaven forbid!).

Defragging isn't the only thing I'd been wanting to schedule to occur regularly. There are a lot of things that I'd like my Windows PC to do for me on a schedule, without having to initiate the process each time. That's when I decided it was time that I make friends with Windows Scheduled Tasks.

By the end of this article, you should have a better idea of a few ways that you can use Windows Scheduled Tasks to get things done on your computer. I'll show you how to setup tasks to defragment your hard drive, restart you computer, open a browsing session in Firefox, and even setup a simple alarm clock.

Getting started with Scheduled Tasks

First off, open your Control Panel and double-click on Scheduled Tasks. Next double-click on Add Scheduled Task to start the dialog for creating your scheduled task. I'll walk you through setting up a recurring disk defrag so you can get the idea, then I'll show you a few variations that you can try out for scheduling other programs.

Setting up a scheduled defrag

At the Scheduled Task Wizard intro screen, click Next. Since defrag.exe is not in the list of programs, we're going to have to hunt it down. Click on Browse..., then go to C:\Windows\\system32\\defrag.exe. Once you've chosen defrag.exe, click Open.

Next, enter the name of this task, something like "Scheduled Disk Defragment" and choose how often you'd like to perform this task. You're given the option to perform the task daily, weekly, monthly, one time only, when your computer starts, and when you log on. Beyond this, there are several other more advanced scheduling options (for example, if you choose to schedule a task daily, you can next choose to run it only on weekdays).

I know there are several schools of thought on how often you should defrag your hard drive (from daily to monthly or more), so I'll leave that for you to decide. Happily, you can setup your scheduled tasks with a lot of flexibility, so no matter how often you decide to defrag, you can set things up and forget about it.

Once you've named your task and chosen when and how often you'd like it to be performed, click Next. You can now set the time. Easy enough, right? I set my computer to defrag the disk in the middle of the night so that it does everything without me ever having to deal with it. Click Next.

Now you need to enter the name and password of the user who will be running this task. The user will default to you, so you probably won't need to change anything in that field. Be sure to enter your password (you do have your computer password-protected, right?) - failure to do so will likely keep your scheduled tasks from working.

You're almost finished. On the next screen, check the "Open advanced properties for this task when I click Finish" checkbox and click Finish. The advanced properties dialog should now be open. In the text area labeled "Run:" you should see an entry that looks something like this:C:\WINDOWS\\system32\\defrag.exe
We need to add the drive that we'd like to defragment; in our example, the C: drive. To do this, just append C: to the end of the Run: line so that when you're finished, it looks like this:

C:\\WINDOWS\\system32\\defrag.exe C:

Another shorter version that's still acceptable is:

defrag C:

Finally, click OK and you're done. If you'd like to give your new task a test run just to make sure everything's setup correctly, right-click on the task (in this case "Scheduled Disk Defragment") and select Run. If all's well, you should see a Windows command line window open up and start the defrag. If you don't want it to run the whole defrag right now, press Ctrl+C to cancel.

Cool, huh? Here are a couple of other quick ideas for ways you can use Windows Task Scheduler.

Automatically restart your computer

Okay, so it's the middle of the night and you've defragged your hard drive and scanned for viruses. Before you get up and start working, though, you'd like that oh-so-fresh feeling that only a newly-rebooted Windows PC can offer. Try this bit of code for your Run line:C:\WINDOWS\\system32\\shutdown.exe -r -t 01.

Start a Firefox session

No matter who you are, if you spend a lot of time on the Internet, chances are you have a set of pages that you visit to start the morning just like your morning paper. You're computer has been freshly restarted and is just sitting there, waiting for you to wake up - why not let it fetch your favorite pages so that your morning reading is ready and waiting for you. Set up a task to open Firefox just as you did above, then add all of the websites you'd like to visit following your run line separated by a space. The resulting line should look something like this:

Since I roll out of bed every morning and immediately start posting to Lifehacker, I also add Lifehacker's craptastic MovableType install to that list. It's an easy way to get straight to the work I need without having to fetch pages or even click on a few bookmarks. (I also schedule a task to open up Snagit for me every morning before I get up.)

Set a Windows alarm clock

Not only can you schedule programs to run, but also individual files. That means if you want a document ready for you when you start work, you can make it so. I've created an M3U playlist for Winamp to open when I'm ready to get up. You could let your music slowly wake you this way, or, to keep things fresh, make sure Winamp is set to shuffle so you get a little variety in your wake-up music.

A few previously-posted items here on Lifehacker detail how to use Scheduled Tasks to put your PC to work for you. See also: