How to Automatically Keep Windows 7 Clean of Obsolete Files

Tina Sieber 13-07-2011

<firstimage=”//”>clean windows 7 filesWindows has a way of collecting virtual dust, a circumstance that has not changed considerably in Windows 7. These obsolete files take up space and contribute to hard drive fragmentation. While neither of this is a big issue, it is an annoyance, one that you can easily take care of.


In this article I will show you a simple way to regularly and automatically clean your Windows 7 system. This won’t require you to install yet another cool tool and is thus low on system resources. At the same time you will also learn how to automatically run other tools for other tasks.

There are several tools that can remove temporary files and keep your computer free from clutter, for example CCleaner Help CCleaner Remove All Your Excess Files With CCEnhancer Add 450 extra programs to the already extensive CCleaner. An unofficial program makes Piriform's famous system maintenance tool even more useful, by vastly increasing the amount of software it supports. CCEnhancer makes CCleaner even better... Read More . However, these programs themselves take up hard drive space and consume system resources, thus adding to the problem rather than solving it. In fact, Windows comes with an accessory utility called Disk Cleanup, which does a pretty good job at freeing up space on your hard drive by removing temporary files, emptying the Recycle Bin, and deleting other obsolete files.

clean windows 7 files

You can run the tool manually by going through > Start > All Programs > Accessories > System Tools > Disk Cleanup. However, you can also schedule an automatic disk cleanup and that’s the procedure I am going to show you in this article.

1. Open Task Scheduler

Go to > Start and type > task scheduler in the search box, then hit > Enter.


obsolete files cleaner

2. Create Basic Task

In the Task Scheduler windows go to > Action and select > Create Basic Task…

obsolete files cleaner

3. Setup Task With Task Wizard

The previous step opened the Task Wizard. In the first window enter a name and description for your task, then click > Next.


obsolete files cleaner

The Task Trigger determines when the task will be launched. In this case I want to the Disk Cleanup utility to run on a weekly basis. Click > Next to set the day and time.

obsolete files problem

When you have decided on a schedule, click > Next to set an Action.


obsolete files problem

Here we want to > Start a program. Select the respective option and click > Next.

obsolete files problem

Enter the link to the respective utility in the > Program/script: field. The link for Disk Cleanup is > C:\Windows\System32\cleanmgr.exe. To run the tool automatically, without requiring your input, also add the command > cleanmgr.exe/sagerun:1 into the > Add arguments (options): field.


autorun program

Click > Next once more to see an overview where you can check your settings and then hit > Finish to save the task. In this configuration, the tool will run with default settings.

4. Change Disk Cleanup Settings

Naturally, it is desirable to change the default settings to suit your preferences. First of all, you basically need to save your preferred Disk Cleanup settings in a profile. Then you manipulate the command in the > Add arguments (optional): field above, to point to the instance of Disk Cleanup you launch with your scheduled task to the profile you created. This way you can set up multiple scheduled tasks, running different Disk Cleanup profiles. Now let’s see how that works.

Click > [WINDOWS] + [R] key combination to launch the Run Windows. Type in > Cmd and click > OK.

change disk cleanup settings

In the DOS-like window that pops up, type in > cleanmgr /sageset:3 where ‘3’ will be your new profile.

command line

The Disk Cleanup Settings window will launch. Select which files you wish to have cleaned, then click > OK to save your settings in a registry key.

customized disk cleanup

Now return to your scheduled task. Launch the Task Scheduler as described in step 1 above. Your task will be listed in the top middle column in the Task Scheduler window. Double-click the task, then switch to the > Actions tab and double-click the > Start a program action. In the > Edit Action window change the number for the > sagerun command to your profile number, for example to > cleanmgr.exe/sagerun:3

clean windows 7 files

That’s it! For more information about how to manipulate the Disk Cleanup utility, check out this Microsoft Support article.

For more tips and tricks on how to keep your Windows system lean and clean, check out these articles:

What tools have you been using to clean your hard drive?

Image credits: Kurhan

Related topics: Computer Automation, Computer Maintenance, Windows 7, Windows Task Scheduler.

Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.

Whatsapp Pinterest

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Roozbeh Razavi
    July 24, 2011 at 8:02 am

    I've a question Tina. Why did you put sagerun:1 in the 3rd step and then change it to sagerun:3 in the last step? You could create sagerun:1 via cmd! Am I right or not? Can you please explain it for me? Thanks

    • Tina
      July 24, 2011 at 12:21 pm


      the number indicates the disk cleanup profile. In the first example I ran profile number 1. In step 4 I explained how to create a new profile 3, using the sageset command. The only new information in that step is how to create a different profile.

      You can manually run sagerun:1 (or any other profile) via the cmd line of course. The whole point of this article, however, was to explain how to automate disk cleanup using scheduled tasks.

  2. Ben
    July 15, 2011 at 6:57 pm

    Can you write a tutorial for CCleaner too?  That would be nice:)

    • Tina
      July 16, 2011 at 12:52 pm


      I have covered CCleaner here:
      Top 5 Freeware Registry Cleaners That Improve PC Performance

      Recently, Justin wrote about CCleaner extensions:
      Help CCleaner Remove All Your Excess Files With CCEnhancer

      • Ben
        July 16, 2011 at 3:49 pm

        I meant write about scheduling Ccleaner to run at a certain time.  Like you did with Disk Cleanup.

        • Tina
          July 24, 2011 at 12:23 pm

          Sorry Ben, only now saw your second comment.

          Essentially, you can use scheduled tasks to run any application. I don't have CCleaner installed right now and I'm not sure whether it comes with an internal way to auto-run. Well, I will check it out and see whether this warrants a new article. Thanks for the suggestion!

  3. Manuel Perez
    July 14, 2011 at 5:51 pm

    Very cool info!  Thanks!

  4. Ankur
    July 14, 2011 at 2:12 pm

    Very informative article. I still prefer ccleaner but this option is good too .

  5. Bruce Epper
    July 14, 2011 at 9:24 am

    Even utilizing these tools the system will still perform sluggishly and will have a great deal of wasted space with all of the uninstall crap that is left on the system as a result of patching the OS and other MS software.  And removing some of the hotfix uninstallers can sometimes break later software patches.  Not a good scene.

    For best results, I generally do a complete reinstall once or twice a year.  Nothing at all can beat that practice, it just sucks if you don't cheat.  Since I'm using Win7, I keep VHDs of clean, fully patched 32-bit and 64-bit systems.  Before doing a reinstall, I sysprep the appropriate image and create a new installation disk that is already fully patched and has the largest software packages preinstalled (MS Office and Visual Studio) which are also already fully patched.  Easily shaves 8 hours or more off of my installation time.  After the reinstall, just put in the smaller software packages again & I am good to go for another 6 to 12 months.

    • Tina
      July 14, 2011 at 3:03 pm

      Re-installing the system of course is the cleanest way to start fresh, but it's not very convenient.

  6. Merrie
    July 14, 2011 at 7:29 am

    ... or you could download and install Wise Disc Cleaner Free, and with 1 click it just does the trick - easy as :)

    • Tina
      July 14, 2011 at 3:01 pm

      As I said, there are many tools that will do this and more.

  7. Anonymous
    July 14, 2011 at 3:11 am

    Still using the manual approach. :)

  8. Anonymous
    July 13, 2011 at 7:40 pm

    Nice tutorial for advanced users.

    • Tina
      July 13, 2011 at 11:50 pm

      Well, I sure hope that it's explained well enough so that also not so advanced users can follow. :)

      • Joe Phillips
        July 14, 2011 at 3:05 am

        I think it is...  I use CCleaner, but knowing how to schedule a task is handy!