Home » All » Maintenance » Vista » Windows | All Categories

Published on 07.18.07 by Brent Trahan

Automate Windows Vista’s Disk Cleanup

This guide shows you how to automate Disk Cleanup in Windows Vista using the Task Scheduler.


An important part of maintaining your Windows Vista computer is routinely running a Disk Cleanup to remove the trash left behind by Windows and software on your hard drive.

Most people don’t think of or want to do things like running Disk Cleanup. This guide shows you how to setup Disk Cleanup to automatically clean your hard drive every week by using a scheduled task.

Automate Disk Cleanup

Set What to Clean Using Sageset

Before you can set disk cleanup to automatically clean your computer periodically you need to tell it what to clean when it performs a disk cleanup. Here’s how to setup disk cleanup to clean your computer based on saved settings.

  1. Open the command prompt by typing cmd in the search box in the Start Menu and then pressing enter.
  2. Type CLEANMGR /sageset:1 in the command prompt and then press enter.

    Using the /sageset:1 switch saves the settings you set in the registry as :1. Disk Cleanup will use these settings when it runs from a scheduled task.

  3. Check off the files you want disk cleanup to clean when you run disk cleanup automatically in the Disk Cleanup Settings window.


  4. Click OK when you’re finished.

Setup A Disk Cleanup Scheduled Task

Now that we’ve saved settings that tell disk cleanup what to clean we can create a scheduled task that automates disk cleanup.

  1. Open the Task Scheduler by typing task in the Start Menu’s search box and clicking on Task Scheduler in the search results.

    Note: If you don’t receive a UAC prompt when you open Task Scheduler close the Task Scheduler and open it again by right-clicking Task Scheduler and selecting Run as administrator. You also need to pay attention to part B of step 5.

  2. Let’s create a new folder on the left side of Task Scheduler called Disk Cleanup by expanding Task Scheduler Library, and Microsoft, and then right-click the Windows folder and select New folder. Type Disk Cleanup as the name of the new folder and click OK to save it.
  3. Expand the Windows folder and click on the new Disk Cleanup folder you just created.


  4. Let’s create a new scheduled task by right-clicking in the white space in the white box located at the top center or the Task Scheduler window and select Create new task.
  5. Give the new scheduled task a name by typing it in the Name box.


    • Part B – If your user account you’re logged in with doesn’t have administrative privileges you must run the Task Scheduler as administrator and follow the steps in part B for disk cleanup to work.
    • Click the Change User or Group button in the General tab of the Create Task window.
    • Click the Advanced button in the Select User or Group window.


    • Click Find Now and select the user you’re currently logged in with from the list of users and groups that show up.


    • Click OK in the Select User or Group windows so that you’re back in the General tab of the Create Task window.
  6. Now we need to tell it how often to run disk cleanup by clicking the Triggers tab and click the New button.
  7. In this example I’m choosing to run disk cleanup on a weekly basis. Check off Weekly, set a time and day of the week to run disk cleanup and click OK when you’re finished. Make sure the time you select task to run is a time when your computer is turned on and logged in.


  8. Now we need to tell the Task Scheduler what to do at the time we just scheduled. Click the Actions tab and click New.
  9. Make sure Action says Start a Program in the New Action window.
  10. Type C:\Windows\System32\cleanmgr.exe under Program/Script and /sagerun:1 next to add arguments. The /sagerun:1 argument loads the settings you saved earlier. Click OK when you’re finished.


  11. Next, click the Conditions tab and check off Wake computer to run this task just encase your computer is sleeping when it’s time to run disk cleanup.


  12. Finally, click the Settings tab and check off Run task as soon as possible after a scheduled start is missed encase your computer is turned off when it’s time to run disk cleanup.


  13. Click OK to save the new task.
  14. Test the new scheduled task you just created by right-clicking it in the Task Scheduler window and selecting Run.

Still need help? Ask your computer question now.

Related Guides:

8 Responses to “Automate Windows Vista’s Disk Cleanup”

Subscribe to this guide's comments RSS feed.

  1. Jake says:

    hello. my disk cleanup or cleanmgr.exe doesnt start when i do it manually or via task. it comes up for a breif second and then vanishes. i have tried in safe mode and still the same effect. any ideas? cheers.

  2. Brent Trahan says:

    Exactly how are you running cleanmgr.exe?

  3. Sven says:

    Hello Brent. This forum is an excellent resource for those of us who are learning more about Vista. Thanks for doing it!

    My question is regarding the automated disk cleanup. I have several external hard drives in addition to on internal drive with two partitions called C and D.

    On which drive should I use disk cleanup: C drive (DOS), D drive (user profiles, my docs, my pictures, etc and other basic data), the external drives (photos, music, etc)

    In other words, does Vista put its “junk” on any particular drive or is it an equal-opportunity dispenser? Or put another way, is there any value to use disk cleanup on a drive that has only music files?


  4. Brent Trahan says:

    Vista has a recycle bin for each drive on your computer. When you delete files on the D drive for instance, the deleted files are stored in a special place on the D drive until the recycle bin is emptied.

  5. Dan says:

    Not sure what I did wrong but after I ran the clean cleanup task, I went to check on cleanmgr.exe program, nothing was cleaned. I did included /sageset:1 argument and in that argument I did set cleanmgr to clean everything. I checked everything. What could’ve gone wrong? Task scheduler told it completed the task with no problem but how come nothing was cleaned?

  6. Brandon says:

    Same issue here, Dan.

  7. Brandon says:

    Oh yeah, when I run the command logged in, the task runs and the files set in the sageset command are cleaned. Do you have to be logged in for the sagerun command to process the registry files?

  8. carol says:

    hi brent! thanks for your advice, but i have a problem, when i have finished created task, it responds that „ an error has ocurred for task Automatic Disk Cleanup. Error message: The following error was reported: 2147942512”. Please help me…. because i always have problems with disk C. I wait your answer!

Leave a Reply

Subscribe to this guide's comments RSS feed.

Microsoft Windows is a registered trademark of Microsoft Corporation. Microsoft Corporation in no way endorses or is affiliated with MAXIMUMpcguides.com. All other products mentioned are registered trademarks of their respective companies. MAXIMUMpcguides IS NOT RESPONSIBLE for any damage or data loss to your computer from using this web site. All information on MAXIMUMpcguides is provided on an AS IS basis with NO WARRANTIES.

Copyright 2006-2019 Brent Trahan. All rights reserved.