Using the Disk Cleanup Handler

Automating Cleanup with Microsoft Task Scheduler

With cleanmgr.exe that you can configure specific tasks to perform the desired cleanups.
To configure Disk Cleanup Manager:
  1. Select Startthen selectRun.
  2. Type the following text in the Run dialog box: cleanmgr /sageset:n, where n can be any number between 0 and 65535.
  3. Select the items that you want to be cleaned.
  4. Select OK.
    Note: You can also create a shortcut in your Windows folder to cleanmgr /sagerun:n (where n is the number in step 2). Type a name for the shortcut (for example, cleanuptask).
  5. If you want to verify the settings, repeat steps 1 through 3.
The following steps apply to Windows XP Professional and Windows Server 2003:
  1. Select Start then selectAll Programsthen selectAccessories then selectSystem Toolsthen selectSchedule Task.
  2. Add the scheduled task.
  3. Select Next.
  4. Select Disk Cleanup or the shortcut that you created in step 2. If you are using the shortcut, select Next.
  5. Select Next and configure.
    Note: You must provide your user ID and password to run this task.
  6. If not using the shortcut, then select the Open advanced properties for this task when you click Finish.
  7. Select Finish when the step is complete.
  8. If you are not using the shortcut, then the Properties dialog box should be displayed. Select the Task tab.
  9. In the Run text box append /sagerun:#, where # is the number from step 2.
  10. Check Event Viewer for any errors under Application.
The following steps apply to Windows Vista and Windows 7.
  1. Select Startthen selectAll Programsthen selectAccessories then selectSystem Tools then selectTask Scheduler.
  2. Select Create Basic Task.
  3. Type a name for the task in the Name field.
  4. Select Next.
  5. Select the appropriate triggers and options.
    Note: Select Next to advance through the trigger options.
  6. Select Actionthen selectStart Program.
  7. Select Next.
  8. Type cleanmgr in the Program/script: text box.
  9. Type the appropriate arguments for :/sagerun:#, where # is the number from step 2.
  10. Select Next.
  11. Select Finish.