Thursday, December 22, 2005

Setting up an automated disk defrag

By: Kerry Garrison

Let's face it, back in the old days sitting and watching Norton
Speed Disk crank away on a 20mb drive actually had some
entertainment value, mostly because it only took a few minutes.
These days, a badly fragmented multi-hundred gigabyte drive may
take hours to defrag. If that's still your idea of
entertainment, then I can bet you don't go on a whole lot of
dates. Let's try and free up your weekends anyway by showing you
how to automate your defrag on Windows XP.

What is a defrag anyway?

Think of your hard drive as a giant wall of mail slots you might
see at a big business. Each slot can hold a small amount of
data. If a file you are trying to save fits into a single slot,
great, no problem. However, if the file is going to require
multiple slots, you begin to get fragmentation if the system
writes one part of the file to one slot but then has to skip
over several slots before there is space for the rest of the
file. The more files you add and delete, the worse this
fragmentation becomes. By defragmenting your drive, the defrag
program rearranges all of the data stored on it so that each
file is in consecutive slots. This makes reading the file in
when you want it much faster.

How do you defrag your drive?

On a Windows XP machine, go to your Start menu, select All
Programs, go to Accessories, select System Tools, and then
select Disk Defragmenter. This will allow you to select each
drive you may have in your system, analyze it , and perform a
defragmentation if needed.

That's all well and good for those people who actually remember
to do this once in a while, but the Naked Computer Guy is
nothing if not lazy. I would much rather be catching up on
TIVO'd episodes of American Chopper than remembering to defrag
my drive, so I created a very simple method to schedule a
regular defrag that I use on all of my client's machines (as
well as my own) these days.

The Automated Defrag

The reason why this is possible is that in the current version
of Window's defrag program, they put back in the ability to run
the defrag program from a command prompt. Armed with this
knowledge, we can create a simple batch file to defragment our
drives, and then schedule the defrag to run at specific times.
Start off by running Windows Notepad. We are going to add one
line in this file for each drive in your system using the format
defrag driveletter: so for most people, this will look like:

defrag c:

If you have more hard drives, just add additional lines for each
drive letter. Now we want to save this file, for simplicity's
sake, let's just save it to the root of your C drive. When
saving this file, be sure you save it as follows:

"dodefrag.bat"

If you do not put the quotes around the name, it will end up
saving the file as dofefrag.bat.text which will not work for our
purposes.

Next go to your Start menu, select All Programs, go to
Accessories, select Scheduled Tasks. Double click on the "Add
Scheduled Task" icon. On the first screen, click on Next, then
click on the Browse button, then double-click on the
dodefrag.bat file, and just to be a bit anal about this, let's
select the Weekly radio button, and click Next.

Since I recommend keeping your computer on 24 hours a day (turn
off CRT's) so that automated updates and maintenance tasks can
run at off-usage hours, let's schedule your task for a time
frame that makes sense to you. I set mine to run at 4am every
week on Sundays. This means that on Monday morning, my system is
all set for me to begin my week.

Once you click the Next button you will be asked for the
security credentials of a user that the program can run as. This
is important because your system may not be logged in or it may
be logged in as a non-admin user when the time comes for the
task to occur. This step is a problem if you do not have any
accounts on your system that do not have passwords, this will
simply generate an error. If you have an account with a password
set that has administrator rights, enter that user name and
password, click Next, then click on Finish, and you have just
automated your defrag process. If you need to create a user with
a password for running these types of tasks, then follow these
steps:

- Go to the Start menu, then Control Panels, then User Accounts

- Click on Create a new account

- Put in a user name (I like to create an account called
Maintenance)

- Click Next

- Make sure Computer Administrator is checked and click Create
Account

- Click on the new account icon

- Click on Create a password

- Enter in a password and hint for this user

- Click on Create Password

- Close the User Accounts window



Make sure the user name in the Schedule Task Wizard screen
matches the new account you created, and then follow the
instructions above to complete the task creation process.

About the author:
Kerry Garrison is the Director of Technical Services for Tech Data Pros, a southern
California IT Consulting firm, and is the publisher of The Geek Gazette and VOIPSpeak.net.

No comments: