• ARTICLES
SEARCH

How-To Geek

How to Schedule Disk Cleanup in Windows 7 & Vista

It’s always a good idea to run regular maintenance tasks like Disk Cleanup on your Windows machine to help keep it running smoothly. Today we take a look at how to schedule a basic Disk Cleanup task, and how to use command line switches for a more advanced setup.

Schedule Disk Cleanup Basic

Windows includes some handy tools to help keep your machine operating smoothly. One such tool is Disk Cleanup that can remove temp and old files to help you reclaim some hard drive space. You might want to set it up to run weekly or monthly depending on what works best for you. To schedule Disk Cleanup to run on a regular basis we need to schedule a task. For this example we’re using Windows 7, but the steps are essentially the same in Vista as well.

Click on the Start Menu and enter task scheduler into the search box and hit Enter.

30disk

The Task Scheduler opens and you’ll want to click on Action then select Create Basic Task.

31disk

The Create Basic Task Wizard comes up and from here type in a name for the task and a description then click Next.

32disk

Now select how often you want Disk Cleanup to run…Weekly, Daily, Monthly, One Time…etc. There is not right or wrong answer to how often you run it. It’s completely up to you and you might want to try out some different schedules. In this example we’re going to select weekly.

33disk

Since we set it up to run weekly we need to schedule it when to start, how often it reoccurs, and which day of the week to run it.

34disk

Next under Action select Start a program

35disk 

In the Program/script field type in cleanmgr.exe

56bas

Or you can hit browse and select Disk Cleanup which is in C:\Windows|system32\cleanmgr.exe

57bas

Under Program/script you’ll see the path to Disk Cleanup as C:\Windows\system32\cleanmgr.exe

37disk

Then you’re shown a summary of the scheduled task and if everything looks correct click on Finish.

38disk

For this basic setting we scheduled it for a time when we know the computer will be in use. When it’s time for the Scheduled Task to occur it will pop up and you can run it by selecting the drive to clean up.

41disk

Disk Cleanup starts its calculations…

42disk

Now the results and you can choose the files to delete.

43disk

Advanced Command Line Switches

While the above method is effective, you may not want to interact with the Disk Cleanup utility at all. Running a couple of command line switches will allow you to select what to have cleaned up and run everything automatically. To open the Command Prompt type cmd into the search box in the Start Menu and hit Enter.

51adv

With the Command Prompt open type in the following:

cleanmgr.exe /sageset:1

That will open the Disk Cleanup Settings dialog box where you can select the items you want Disk Cleanup to delete. You’ll notice there are a lot more options here than when you go through the GUI to cleanup files.

52adv

After selecting the files you want to be deleted in Disk Cleanup Settings click Ok to close out of the screen. The /sageset:1 command creates a registry key that saves the settings you entered.

Now go in and create your Scheduled Task like we showed previously, but this time you’ll want to add in /sagerun:1 into the Add argument field.

55adv

Now when Disk Cleanup runs it’ll retrieve those saved settings you created with /sageset:1 and you won’t need to interact with Disk Cleanup at all. It will run automatically and clean up the files you selected in Disk cleanup Settings.

Task Scheduler Error

When you launch Task Manager in Windows 7 you might get the following error message. It tells you to hit refresh but the error keeps coming back. It doesn’t seem to negatively affect anything you schedule, but it’s quite annoying.

39disk 

From the research I’ve done on this error, there are a handful of different solutions that have worked for different people. On our system, the Disk Defrag Schedule was turned off, so we turned it back on and resolved the issue. On a separate Windows 7 system the Disk Defrag Schedule was already on (which it is by default) and turning it off cured the error. On another machine I had to turn it off then back on to fix the error message.  

50disk

Since this “rub your head and pat your belly” approach worked we didn’t try any other possible fixes. If you find it doesn’t work or have found another solution let us know in the comments.

Conclusion

If you use the advanced switches to run Disk Cleanup it actually offers a lot more choices. In the /sageset:1 switch, “1” is just an arbitrary number. You can enter any number you want, but make sure /sagerun:”x” corresponds to the number you used in /sageset:”x”. So you can customize the switches for different types of files you want to clean in Disk Cleanup Settings.

For example, maybe you only want to clean Temp Internet files during a cleanup session, then you could do /sageset:1 and /sagerun:1 for that. Then if you want to clean up all files you could use /sageset:10 and /sagerun:10 for that. The switches give you more flexibility in the types of files that are deleted during the Disk Cleanup session. Whichever method you use, or if you just want to run it manually, running Disk Cleanup will keep your drive free of unwanted files.

Lowell Heddings, better known online as the How-To Geek, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on if you'd like.

  • Published 02/15/10

Comments (17)

  1. David Dashifen Kees

    Any way to specify the drive on which to run cleanup when using the /sagerun command line option?

  2. Bryan

    Can it work on XP?

  3. GKI610

    DDK, are you asking in the case of: I want it to run when the computer is unattended?

  4. InDiSent

    I think DDK means another drive like D:/

  5. Mysticgeek

    @Bryan: Yes it will work in XP as well, the steps are just a bit different when scheduling the task.

  6. SquareWheel

    Nice, informative article. Thanks for the tips.

  7. raidex

    thanks .. very useful tip.

  8. jake

    this is great!! i was sick of doing this regularly!! thank you for this tip.

  9. kake

    Do I have to be logged in as administrator when I setup this task and when the disk cleanup is running?

  10. kake

    How can I delete a scheduled task?

  11. Anton

    Does /sageset and /sagerun can be used for others microsoft windows’s programs ?

  12. paul sosney

    This is all well and good but I want to change the scheduled cleanup and can find no way to edit or delete Disk Cleanup from the Task Scheduler.

  13. Tom

    Dumb question, but where (in the task scheduler) is this stored? I need to change the time I originally scheduled the Disk Cleaner, and for the life of me, can’t find it? Since there’s no (obvious) way to “view all scheduled tasks,” since they’re organized by category, and no way to “search” (that I can find), and no (obvious) category for tasks created using the “Create Basic Task” wizard, it’s as if this scheduled task has been lost in the bowels of the task scheduler.

    Thanks in advance for any help!

  14. Kasou

    Maybe this only works if you are using English OS,

    Use Command line ‘Taskschd.msc’

  15. sweidre

    Hi DDK & inDiSent,
    I used literally the description regarding “Advanced Command Line Switches”, and the ticked options for Disk Cleanup turned up to be for all my drives. The automatic cleanup was done for all my drives C: D: E: …etc. including drives attached to USB ports, RAMdrive, and Dropbox-drive. (I have no VHD, so I do not know, if also such a drive will be included?!)
    Thanks a lot for this article!! Super!
    Regards,
    sweidre

  16. Vikas

    thx for sharing the technologies, pl mail me for any help

  17. ansijoshi

    thanks it helped a lot!

Enter Your Email Here to Get Access for Free:

Go check your email!