AUTOMATING THE DISK CLEANUP TOOL

If you do the preceding setup steps, the Disk Cleanup tool starts automatically at the specified time. However, it does not run automatically because it requires human intervention to confirm before deleting data. That's the case with most utilities.

However, in the case of Disk Cleanup, there's a way to make it fully automated, by preentering your preferences of what to delete. Follow these steps to try it out.

  1. Schedule Disk Cleanup to run (see the preceding section).
  2. Select Start > Run. In the Run box, type cleanmgr /sageset:1, and then click OK. (Actually you can use any number here, from 0 to 65535.)
  3. In the Disk Cleanup Settings dialog box that appears, mark the types of content you want to automatically delete during the cleanup process, as shown in Figure 6-4.
Figure 6-4: Disk Cleanup Settings dialog box.
Figure 6-4: Disk Cleanup Settings dialog box.
  1. Mark the checkboxes for the content to be automatically deleted, and then click OK.
  2. In the Scheduled Tasks window, double-click the icon for the scheduled Disk Cleanup task to open its Properties dialog box.
  3. On the Task tab, add /sagerun:1 to the end of the command in the Run box, for example:
C:\WINDOWS\system32\cleanmgr.exe /sagerun:1
  1. Click OK. If prompted to reenter your password, do so, and then click OK.

The reason you can put any number with sageset and sagerun is that you can create different preference sets to run at different times. Each numbered set could have a different scheduled task entry.

Now when Disk Cleanup runs, it should run automatically with the settings you provided. The previous steps will run Disk Cleanup on every eligible drive; if you want only a certain drive, add the /d x : switch also, where x is the desired drive letter.