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.
Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.
We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats (video ads) or subscription fees.
If you like our content, and would like to help, please consider making a contribution:
Ghacks is a technology news blog that was founded in 2005 by Martin Brinkmann. It has since then become one of the most popular tech news sites on the Internet with five authors and regular contributions from freelance writers.