Last week I explained how to schedule the Disk Cleanup utility to perform basic maintenance tasks. But the Disk Cleanup utility can be overkill, and in some cases you might not want it to run through all its options. How can you tell it you just want it to just clean out the Windows Temp folder? The answer is found in some amazingly useful command-line switches that most Windows users know nothing about. (They’re documented in Windows XP Inside Out and in Knowledge Base article 315246, How to Automate the Disk Cleanup Tool in Windows XP.)
To control how the cleanup process works, you need to first know the executable command for the Disk Cleanup utility, cleanmgr.exe. Then you need to learn to use the following switches to modify its behavior:
- /D driveletter Runs Disk Cleanup using the drive letter you specify in place of driveletter (for example, type cleanmgr /d c:, to apply the utility to drive C). (This option is ignored if you use the /Sagerun switch.)
- /Sageset:n Opens a dialog box that lets you select Disk Cleanup options, creates a registry key that corresponds to the number you entered (where n is an arbitrary number from 0 through 65535), and then saves your settings in that key.
- /Sagerun:n Retrieves the saved settings for the number you enter in place of n and then runs Disk Cleanup without requiring any interaction on your part.
To put all the pieces together, follow these steps:
- Click Start, Run (or open a Command Prompt window) and type the command cleanmgr /sageset:200. (This number is completely arbitrary; you can choose any number from 0 through 65535.)
- In the Disk Cleanup Settings dialog box, choose the options you want to apply whenever you use these settings. In this example, I’ve cleared all the check boxes except the one in front of Temporary files.
- Click OK to save your changes in the registry.
- Create a shortcut that uses the command cleanmgr /sagerun:200. Save the shortcut in the Windows folder using a descriptive name – Clean Temp Files, for instance.
- Open Control Panel’s Scheduled Tasks folder and start the Add Scheduled Task Wizard. When prompted to select the program you want Windows to run, click Browse and select the shortcut you just created. Follow the wizard’s remaining prompts to schedule the command to run at regular intervals.
- Repeat steps 1–5 for other Disk Cleanup options you want to automate.
That’s it. As long as the Task Scheduler service is running, your cleanup chores will be handled automatically on the schedule you specified.