Wednesday, October 18, 2006

Windows XP: Automate the Disk Cleanup Tool

In a previous article I talked about the Disk Cleanup tool, which is designed to remove unnecessary temporary files from your computer. These files are created by applications to temporarily store data, but sometimes they don't get cleaned up correctly.

Now, I am going to show you how to automate this process. Its relatively easy to do, all you have to do is follow the instructions below:

Configuring the Disk Cleanup tool:
  • From the Run... command, type "cleanmgr /sageset:1" and press the OK button.
    • You can have up to 0 - 65535 profiles, all you have to do is change the number after '/sageset'. Make sure you remember the number you selected for the profile you will need it for the next section.
  • When the Disk Cleanup dialog displays, select or unselect the type of files that you want to remove when the tool is run.
  • Press the OK button.
Running the Disk Cleanup tool:
  • From the Run... command, type "cleanmgr /sagerun:1" and press the OK button.
    • Make sure to use the session number (i.e.: 1 in the example above) for the Disk Cleanup profile you created in the previous section.
The Disk Cleanup tool will now remove all the files as define by the profile you created.

The 'cleanmgr /sagerun:1' command can be run from the MS-DOS prompt, added to a script, or run from the 'Scheduled Tasks' feature on a regular basis.

1 comment:

Gary Erdman said...

Excellent tip. It works exactly as published (which seems rare these days). Anything that can be automated and then forgotten about is worthy of my vote for best tip. I wonder why Microsoft help documentation doesn't mention this type of thing?