One of the easiest ways to keep your computer running smooth is to make sure your hard drives arent fragmented to death. I know, I can already hear all the Mac and Linux people screaming at me about how unimportant defragmenting your drives is but trust me, as a Windows veteran I know first hand just how large a difference a good defrag can make. Only down side is that it takes too long to do it and just like cleaning the house, nobody actually wants to do it. Well, your all in luck because you can make Windows clean itself, man I wish the house could do that too…lol. Scheduling a defrag can be done in Windows 98/ME/XP for sure, as for Vista and 2003 I can’t say cause I’ve never tried this on those OS’s. I do know that this can’t be done in windows 2000. 2K is missing the command line defragment interface needed to schedule a defrag.
There are two ways to do this, I’m going to show you the way I like to do it which is to write a script and then set a Windows schedule event to run the script at a determined time. Ok, enough talk, lets get to the good stuff.
The first thing we need to do is to create our script os go ahead and open notepad. Type in the following text, save the file as a .bat file (lets call it defrag.bat) and exit notepad.
defrag c:
The next step is to open the Windows task scheduler, it can be found in the Control Panel. What are you waiting for, open the Control Panel and double click on “Scheduled Tasks”. Now just drag your newly created script into the scheduled tasks window.
It should show up like this…

There are still some changes for us to make, lets start off by double click on the newly created task (defrag_c in this example).
On the task tab click the set password button and enter the password of the user that you are logged in as. You can also change the user that this task will run under, for example, if you are not logged on as an administrator you can enter %machine name%/administrator as the username and then set the administrators password. Just a note, %machine name% is just my way of saying that you will have the name of your PC there, don’t actually put %machine name% in there…lol.
Everything on the settings tab should be fine so let’s head over to the schedule tab and set up when the task should run. I like to run it once a week at 2am on Mondays. This way I start each week with a nicely defragmented hard drive. Set yours up to reflect something that works for you.

That’s about it, there are some other things to consider though. The main one being that this can take a long time and the lower the amount of free space on the drive the longer it will take for this to complete. I forget the % free that you absolutely need to be above but there is a minimum amount of free space that needs to be there before a defrag can even run. Another thing to consider is what else is running when this starts. In my case for example, I have Sage TV installed (another cool app but that’s for another post…lol.) Anyways, I wanted a way to stop Sage TV before defraging its drive starts. To do that I simply created another script to stop the app and a third to start it again 5 hours later (5 hours being a safe amount of time as I know defraging that drive takes a good amount less time than that. The code to put in these scripts are as follows…
Stop the app
tskill sagetv
change sagetv with the process name of the app you want to kill.
Start the app
“C:\Program Files\SageTV\SageTV\sagetv.exe”
change this to the path of the app you want to start.
Well there we go, that’s pretty much all there is to it, now go setup your own defrag schedules and keep your systems running nice. Remember, a defragged hard drive is a happy hard drive!!!
Later all,
Ed.