Scheduling a Weekly Defrag in Windows XP

Uploaded by LeoNot on 03.01.2011

So, what I was talking about earlier was that you all probably know how to do defragmenting.
And, the normal way to defrag your disk is to hit properties, on the drive, hit tools, and click on defragment now.
The issue with that is simply that it is a manual process.
And, I'm a big fan of automation. Especially when it comes to maintenance.
So, the chapter that I was just writing in the book; that I decided to show to you as our first little exercise today,
is how to automate that process.
And, one of the neat validations that I get for automating that process is the fact that in Windows 7 it is automated by default.
In Windows 7, once a week, your machine will automatically run a defrag for you.
What we're going to do is set that same thing up in Windows XP.
Where you'll go is control panel.
You may see a list of options, depending on what kind of control panel view you have.
In this particular case, I have stuck with the defaults, as I suspect most of you have.
What we're looking for is in performance and maintenance: scheduled tasks.
We're going to add a scheduled task.
What Windows does when you do this is provide you with a list of programs that it thinks are common, I guess, to be scheduled.
Unfortunately, the disk defragmenting program is not on this list.
So instead, what we're going to do is browse. And, it's going to be easier if I just type this in.
So, what we're looking at here is C:\windows\system32\defrag.exe
That is the program that we want to schedule.
We're going to do this weekly.
I'm going to schedule this for Sunday at 6pm.
Now, the reason that I choose this time is that, as an example, its a time that your computer needs to be on and running.
I'm choosing dinner time on Sunday because its a convenient time where perhaps the computer will be on,
but I will be away for dinner.
In your case, pick a time that makes sense for you.
My machines typically are on 24hrs a day anyway so I have it happen automatically overnight.
If you have some kind of regular schedule to your computer make sure that it fits within that.
Defrag may impact the speed of the computer if you are trying to use it at the same time.
Now, what its asking for here is your log in ID for the computer.
Don't let the strange user name fool you. Its really your user name on that computer preceded by the actual name of the computer.
The reason it needs the login credentials is that you may not be logged in, even though the computer is running, when it comes time to run this scheduled task.
So what windows does when it schedules a task, when it runs a task,
it simply logs in with the credentials that you give it here.
So, we think we're done, but we're not. And that's why this option is here.
Open advanced properties for this task when I click finish
because there's one piece of information that we haven't given to the defrag program that we still need.
The advanced properties, the details that we have here, are going to let us to change the command line,
and what we're going to do is add a space, a C, and a :
What that's doing, is telling the defrag program which drive you want it to defragment.
That's the only change we're going to make here. You can change other things later if you want to come to change the scheduling or your settings.
And, in fact, I'm going to click OK here. It's asking me for those credentials again.
And now we have a scheduled task.
To modify that later, you would hit properties. And that would bring you back to this advanced properties dialog we just had here.
You can run the task immediately if you want to, or manually at any time.
But for the most part, we have here now, is exactly what we set out to get.
At 6 o'clock, every Sunday, once a week, its going to run the defrag program.
Now, in case you're wondering, what we used was just the command line version of the defrag program.
So, in fact, if you ever feel so inclined, you could start up a windows command prompt and defrag the machine manually.
For those of use that are familiar (or more comfortable) with the command line, this is actually what we end up doing.
I find this much easier than going through the windows user interface, through windows explorer.
But that's all we're doing, we're running a command line program on a schedule using this task scheduler.
Now, Jack asks, "How can you make the computer wake for a scheduled task from hibernation?"
The answer there is: You can't. The computer actually has to be running.
There may be some tricks to do with network booting and those kinds of things,
but for the most part, the short answer, the easy answer, is that the computer actually needs to be running.
It can't be off, it can't be in hibernation and it can also not be sleeping.
I believe that there are some computers where you can actually configure the task to wake the computer from a sleep, but I don't believe that's the case in general.
So that is scheduling automatic defrag once a week.