Clear Temporary Files during System Shutdown

Martin Brinkmann
Oct 28, 2007
Updated • May 21, 2014

Windows does not automatically delete temporary files during system shutdown. This means that temporary files remain on the system's drives for as long as you don't remove them manually or automatically.

While that may not be a huge problem if you have lots of space, it may still be desirable to clear temporary files for privacy reasons.

Since files are not deleted, they remain accessible in the trashcan or Internet caches, which means that anyone with local access to the computer can access those files as well.

System cleaners like CCleaner or Disk Cleaner are able to delete those files but I would like to highlight a method that requires no third-party software to do so, as Windows ships with the right tool to delete temporary data on shutdown as well.

We are going to configure the Disk Cleanup Settings in Windows to delete temporary files and create a new rule using the system's Group Policy to run it on shutdown so that the files get automatically deleted whenever you shutdown the PC.

Our first step is to open the Disk Cleanup settings and configure them the way we want. To do that you use the Run command in Windows XP / 2000 or the search in Windows Vista and newer versions of the operating system.

cleanmgr /sageset 1

This opens the Disk Cleanup Settings. Check the elements that you want to automatically delete. If you are unsure about an element click on it and read the description. This should give you a good understanding of it.

Once you have made the selection and clicked on ok to delete the files, you can continue with the next step.

Open the Group Policy Editor now. You do that in the same location where you started the Disk Cleanup Settings but use the command gpedit.msc instead.

Note: The Group Policy Editor is only available in professional versions of the operating system. If it is not available on yours, use the Task Scheduler instead for the purpose.

Navigate to User Configuration > Windows Settings > Scripts (Logon / Logoff) and double-click on Logoff.

Click on Add and Browse in the next window. Right-click in the blank space of the Logoff folder and create a new text document. Name it cleanup.cmd. Open it with a right-click and add the following line to it.

cleanmgr /sagerun 1

Select the file cleanup.cmd and click Open and in the previous menu OK. The file that you created should be now in the list. Click on Apply and OK afterwards. Et Voila, we are done.

All items that you selected during the configuration phase will now be deleted on every system shutdown.

How to clear temporary files automatically on shutdown in Windows
Article Name
How to clear temporary files automatically on shutdown in Windows
While you can use CCleaner and other third-party software to clean files automatically, you can also use Windows' Disk Cleanup Tool for that.

Previous Post: «
Next Post: «


  1. Harry said on December 31, 2008 at 2:22 pm

    Thanks for procedure to delete tmp files at shudown, it was great.
    Best wishes for New Year

  2. asdf said on December 26, 2007 at 11:39 pm

    This thing makes shutdown take forever. Stick with the a batch file.

  3. Ace_NoOne said on October 28, 2007 at 11:35 am

    I’d tried a very similar method a while ago – though that one used a batch file with the following contents:
    RD /S /Q %TEMP%

    However, that didn’t really work perfectly (there were always a few files and folders left after a reboot), so I will give this a try now.

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

We love comments and welcome thoughtful and civilized discussion. Rudeness and personal attacks will not be tolerated. Please stay on-topic.
Please note that your comment may not appear immediately after you post it.