2

I've been poking around trying to get Disk Cleanup to run when my Windows XP Pro SP2 machine shuts down.

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.

So far, I have attempted to automate Disk Cleanup using a user logoff script in the Group Policy Editor (as per these instructions using cleanmgr /sageset:1 and cleanmgr /sagerun:1), but it doesn't seem to be executing correctly.

In particular, I'm seeing log entries such as

Execution of GPO scripts has timed out and have been terminated."

that suggest the script isn't completing successfully. Also, when I ran the command that the script contains I left my computer for a while. On my return, I found it had shutdown and not completed the Disk Cleanup.

Why doesn't Disk Cleanup appear to be executing correctly, or is there a better approach?

After a bit of fiddling around, it seems that the timeouts were caused by the large amount of temporary files and the amount of old files to compress. I've not been able to reliably duplicate the shutdowns I've been getting when running the cleanmgr command, but suspect it was also related to the timeouts.

However, Disk Cleanup doesn't seem to be cleaning C:\Documents and Settings\Chris\Local Settings\Temp\ as I expected it would. While all other temporary files/folders appear to be cleaned, this particular folder is seemingly untouched.

As I suspect that Disk Cleanup simply isn't meant to clean that folder (although, I don't understand why that wouldn't be the case), I have asked a more general question about how to automatically delete the temporary files in Local Settings\Temp.

2 Answers 2

4

The group policy method should work. You say you "currently" have 3 GB of temp files - if that's the case, delete them and re-test. It's possible that is causing the time out of the script.

You also could try CCleaner (or similar). CCleaner will be more thorough than cleanmgr, being familiar with modern programs.

If you can't get group policy to work you can run it with something like Xecutor or just use CCleaner's built in "Run on start up" option for the same effect. Task Scheduler would work too.

Or if you don't want yet another process hogging your resources in the background (and you think you can remember to use it!) make a batch script along the lines of:

REM Run CCleaner silently
CCleaner.exe /AUTO
REM Shutdown after 600 seconds - tune to suit
shutdown -t 600

Not elegant, but pretty lightweight.

1
  • As mentioned in the update, the timeouts do seem to be caused by the large number of files, and I believe I've sorted that now, so +1 for that, but Disk Cleaner doesn't actually appear to clean the directory I want - there are still .tmp files with modification dates from 2003 in there! Nov 16, 2010 at 19:36
2

Try using Task Scheduler. Instructions on adding tasks on shutdown can be found here.

2
  • By the way, I tried setting it up on my own machine and verified that disk cleanup can be run using Task Scheduler. Nov 16, 2010 at 13:32
  • 1
    A much belated +1, as I seem to recall I tried this approach and it does indeed work Jul 17, 2012 at 8:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .