Windows XP – How to Automatically Execute Disk Cleanup on Shutdown

automationmaintenancewindows xp

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.

Best Answer

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.

Related Question