LordKingSquirrel.com



Automating Windows Disk Maintenance Tasks

February 12th, 2008 · No Comments

Tagged with:  

Over the weekend I was talking about people not defragging their drives or running disk cleanup on their PCs very often. I am of the opinion that most people don’t for two reasons - either they don’t know how/don’t have permissions xor it is inconvenient to do it.

For those in the second camp, here’s a couple of quick tips to make it less painful.

Disk Cleanup

There is a method of using the disk cleanup utility that doesn’t get a lot of press - from the command line. The executable is cleanmgr.exe, and it has the following switches:

  • /d driveletter:
  • /sageset:n
  • /sagerun:n

/d
The use of this switch is pretty straight forward - just specify the drive letter, i.e. cleanmgr /d C:

/sageset
This is a little more complicated, but still very easy. The n parameter is an integer between 0 and 65535 and is used to store your settings in the registry. When you execute the command with this parameter, you will see the “Disk Cleanup Settings” dialog. The syntax is cleanmgr /sageset:n

Clean Manager Dialog

The dialog is basically the same as if you run the Disk Cleanup Wizard - the only real difference is that it doesn’t inform you of how much space each type of file is currently using.

/sagerun
This is the switch you use when running the cleanmgr.exe as a Scheduled Tasks. It’s quite easy to set up as shown below.

Cleanup drive scheduled task

Disk Defrag

Windows XP added a command line executable called defrag.exe. The switches available and their functions are:

  • -a :Analyze only
  • -f :Forces defragmentation of the volume regardless of whether it needs to be defragmented or even if free space is low
  • -v :Verbose output
  • -? :Display the help text

Setting up the job is again pretty easy:

Defrag job definition

Scheduling Tips

On my workstation, I set these tasks to run over the weekend, but you could set them to run as often as you wish. Remember that the cleanmgr utility will often take quite some time to run, so after hours or weekends is a good bet. Likewise the defrag utility can take a long time depending on how badly fragmented your drive is, how large it is, and how fast (or slow) it is.

You could experiment a little, or just schedule them for the weekend. Either way, you will have the benefits of these regular maintenance items without the hassles of running them interactively.

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment