Clear Temporary Files during System Shutdown
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.
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.
This thing makes shutdown take forever. Stick with the a batch file.
Thanks for procedure to delete tmp files at shudown, it was great.
Best wishes for New Year