Delete temporary files/folders automatically in vista and xp

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?

Who is Participating?
Great quick instruction set on doing just that during a shutdown:
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.

RETAILREALMAuthor Commented:
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?
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

What command are you using to setup the cleanup options?

It isnt hanging at "Compress old files" is it?
RETAILREALMAuthor Commented:
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
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
RETAILREALMAuthor Commented:
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?

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....
RETAILREALMAuthor Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.