One of the things that I noticed with my desktop computer is that I’m constantly deleting large files, and after awhile it can consume quite a bit of space. I restart the computer a few times each week, and I decided that upon startup would also be a good time to have the Recycle Bin emptied.

After I started searching around I found that there wasn’t a special command designed to empty just the Recycle Bin. I did, however, stumble upon a way to execute the Disk Cleanup Wizard via the command line in a way that requires no user interaction. That means I could not only empty the Recycle Bin, but also temporary and other unneeded files.

Here’s what you have to do:

  1. From the command line run this line of code:
    C:\WINDOWS\system32\cleanmgr.exe /sageset:1
  2. A window should appear where you can configure what items you want cleaned/emptied when this profile (that we’ve designated as number 1) is run. Check the boxes for each of the options you want executed. Press OK when finished. Note that the Disk Cleanup will not run after you press OK.
    disk cleanup-1.png
  3. Now you need to create a scheduled task. In Vista the action you’ll want to assign will be:
    C:\WINDOWS\system32\cleanmgr.exe /sagerun:1
    And it should look something like this when entered in the New Action screen:
    new action.png
    If you’re asked whether you want to run the program with the /sagerun:1 arguments you can press Yes.
  4. Now you can choose the rest of the settings yourself, such as when you want this to run. One of the options you can pick is to execute this when your computer starts.
    task schedule.png
  5. You’re done!

As you can imagine this tool can clean up a lot of different areas on your PC according to whatever schedule you setup. I’ve also started backing up my entire PC each night, and I have this script run before the process is initiated to ensure that unnecessary files aren’t being backed up. So it’s become a rather critical part of my daily routine.

There Are 14 Comments

  1. Why not just shut the recycle bin off, since your system virtually defeats its purpose in any event. It much faster if you do not store the stuff in the first place than it is to store it and then delete it! Personally, I let my bin take care of itself, and I have an average of three months of files to fall back on, and have many times been delighted that I did. If you want to avoid having large files fill the bin, and then force out all the stuff you might care about, just hold down “Shift” when you select delete. They never go in the bin.

    • just-because-doofus

      This person wants to setup a daily task to do this at a certain time. It’s just his preference. Leave him alone. Stop criticizing him. He is a good person. I know him.

  2. I run crap cleaner in automatic mode at startup which
    I think accomplishes the same thing.

  3. i use BinManager ([]) which has a scriptable component that can be used in vbscript, jscript AutiIt etc…I then use this in a logoff script to empty the recycler at logoff.

  4. CCleaner has this function too, for those who don’t like the look of CMD prompt. :D

  5. Anonymous wrote:
    Why not just shut the recycle bin off, since your system virtually defeats its purpose in any event.

    That’s definitely a valid point, but the Recycle Bin is still useful in case I delete a file, and then want it back later that same day. I want to have the option to retrieve files that I’ve deleted over the past few hours.

    David Gray wrote:
    I run crap cleaner in automatic mode at startup which
    I think accomplishes the same thing.

    Didn’t think about using CCleaner, but I wanted to accomplish this without a third-party app.

  6. I am using Windows Vista home edition, My recycle bin gets automatically empty on restart of system, pls help how do I avoid it.

    - Aravind

    • Is this a work or personal machine? I think this can be controlled by administrators remotely, but you should be able to change that if it’s your own machine.

  7. very nice find, im glad i can do this from within windows without any extra programs

    as to the person wondering why use this method (rather than disabling the recycling bin completely) the answer is simple
    if i delete something on accident i can get it back as long as my computer stays on, but if i delete something on purpose it is unlikely i will need it back by the time i restart my computer
    also this trick cleans up more than just the recycle bin, and since i hate temporary files im glad they are off my system at startup

  8. yeah but what if you delete something and get a bsod? your screwed if you need it back.

    unless your smart enough to go into safemode.

  9. Is there a way to make this run silently so users can’t cancel it?

Leave Your Comment

Message is the only required field.
Emails are not published.