Windows – Automatically deleting ‘C:\Documents and Settings\user\Local Settings\Temp’

automationmaintenancetemporary-fileswindows

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?

Best Answer

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.

Related Question