We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


Delete temporary files/folders automatically in vista and xp

Medium Priority
Last Modified: 2013-11-29
There are too many posts on this subject and many of them give obsolete ideas. Hence I am posting this again as I dn't have time to go through all the posts.

How can I dete the temp folders/files during shutdown or restart in Windows Vista and XP?

Watch Question

Great quick instruction set on doing just that during a shutdown:


Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
I can't really improve on that answer, but I can offer this additional tidbit:  If you have a machine with multiple user profiles (such as a terminal server) you can clean them all at once with a handy utility called ICSWEEP (about a third of the way down the page).  It's freeware, and it's command line; thus easily scripted.



Hi Flubsster,
The solution has worked on my Vista Business machine but it is not working on XP SP2  machine. I dont' mind giving the points to you. But do you have any suggestions to make about XP machines?
Most Valuable Expert 2011
Top Expert 2011

What command are you using to setup the cleanup options?

It isnt hanging at "Compress old files" is it?


Hi johnb6767,
It takes 20 minuts to shut down. It does not matter if the compressed files is checked or not.
The temp folder on C dive is not emptied. It has got lot of PREFETCH files and lot of other files with the extension .TMP.
We manually added some fils with extension "TMP". But these are not getting deleted even if we shift the system date by a year ahead and then repeated the procecure. we are using a batch file as pointed by flubbster above which has the follwing code

cleanmgr /sageset 1
Most Valuable Expert 2011
Top Expert 2011

That sets the options, and then the actual command to run the cleanup is going to be ......

To set options

cleanmgr /sagerun:x  (where x is the set of rules)

To run the cleanup....

cleanmgr /sagerun:x


Hi johnb6767,

we have tried cleanmgr /sageset 1.

This is not emptying the temp folder. You have mentioned that 'x' is the set of rules.
Can you provide and example of what the rules are?
Most Valuable Expert 2011
Top Expert 2011

cleanmgr /sageset:1
Disk Clean up pops up, and then you select your options......

That becomes configuration 1.

If you want to run Configuration 1, you will enter.....

cleanmgr /sagerun:1

You can have multiple configurations, just do the next one with /sageset:2, /sageset:3 etc... Then use the /sagerun:2, /sagerun:3 etc....


All temp files are still not getting cleared. But I guess the method of automating the clean up has been explained properly. Hence I am accepting the solutions and closing the issue.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.