Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to find a way to automatically clean/delete the temporary files from C:\Documents and Settings\user\Local Settings\Temp\ at shutdown/boot on my Windows XP Professional x64 SP2 machine.

The main reason for this is to clean Local Settings/Temp to remove old junk automatically. (I had thought I had this covered through Firefox settings, but I was only clearing temporary Internet files). Currently, there's around 3 GB of temporary files, and I'd like to prevent this build up without having to remember to do anything on my part.

I have already looked at using Disk Cleanup (explained in Super User question Automatically executing Disk Cleanup on shutdown), but it doesn't seem to touch that directory.

I'm aware of programs such as CCleaner, but I would ideally like to use a solution that doesn't require additional software (so, I expect, something using a scheduled BAT/CMD script would be what I'm looking for).

One of the potential issues, I believe, is that there may be legitimate files in the Temp folder that may be needed on the next boot (for software installations or updates, for example) and the perfect solution would be able to distinguish those and leave them until they weren't needed (Note: I realise this perfect solution may not be reasonably possible).

I've already set up Disk Cleaner on a shutdown script, but when cleaning temporary files, Disk Cleaner doesn't clean this particular directory, and so I'm looking for alternative options (see Super User question Automatically executing Disk Cleanup on shutdown for a little more detail).

So, what are my options for automatically deleting the temp files from C:\Documents and Settings\user\Local Settings\Temp?

share|improve this question

3 Answers 3

Take a look here:

In brief (see the above links for more information):

  • Create a batch file, say it's saved as c:\dev\on-shutdown.bat
  • Open the Group Policy Editor - Start / Run, gpedit.msc
  • Go to Computer Configuration / Windows Settings / Scripts (Startup/Shutdown)
  • Double-click Shutdown in the details pane
  • In the Shutdown Properties, click Add and type the above script path in Script Name

I found a representative image in this post:

enter image description here

Hope that helps.

share|improve this answer
    
I should have mentioned that I've already set up Disk Cleaner on a shutdown script, but when it deletes temporary files, it doesn't alter the directory I'm interested in –  chrisbunney Nov 17 '10 at 10:30
1  
Did you try the solution outlined in the above script? Basically, put del /s /f "C:\Documents and Settings\user\Local Settings\Temp" in deltemp.bat file and make it run on shutdown as described in the post. Be very careful to make the bat correct, as del /s /f will delete it mercilessly –  icyrock.com Nov 17 '10 at 14:06
    
-1 for link only answer. Please include relevant parts of the solution. –  Thomas W. Sep 23 at 11:45
    
Thanks @ThomasW. - agreed, added more information to the post itself in case the links go down. –  icyrock.com Sep 28 at 14:11

Tell me if I'm wrong about your intent, but it seems like you want to be able to leave no trace of your logon session. In that case, I would suggest running a virtual machine through one of the many virtual server packages. I personally use VMWare Server 2.0.2, for historical reasons. I have several VMs, and if I want an erasable session, I just take a "snapshot", start the VM and do whatever, shut down, then "revert to snapshot" afterwards. The machine image looks like it did before I logged on.

Alternatively, you can install CCleaner and set it up to run on a schedule. This may be more inline with your question.

share|improve this answer
    
Not so much deleting all trace of my login session, as automating some of the general housekeeping tasks that ought to be done. It seems XP doesn't delete these temporary files, and since they're temporary, I'd like to clear them after each session –  chrisbunney Nov 17 '10 at 10:29
    
On your original question, respondant bitslave suggested you try CCleaner, did you? Run it manually once, see if it cleans the folder in question. If it does, follow his suggestion to automate it, or use CCleaner's ability to schedule the cleaning. I know you don't want additional software, but its a small footprint compared to the 3GB temp files being left behind. –  Robert Kerr Nov 17 '10 at 14:39

My solution was to add Task Scheduler task with needed options and this VBscript as the target:

deltemp.vbs

Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder("C:\Documents and Settings\user\Local Settings\Temp\")

for each f in folder.Files
   On Error Resume Next
   f.Delete True
   On Error GoTo 0
Next

For Each f In folder.SubFolders
   On Error Resume Next
   f.Delete True
   On Error GoTo 0
Next
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.