How to clean temporary Internet files with a log off script

The temporary Internet Files folder on your computer is a dynamic place, every time you visit a website on the Internet, all the web files composing that website get transferred from the hosting server to your computer Temporary Internet Files folder. that includes audio files, pictures and documents. so if you surf a lot on the Internet that Temporary Internet File folder get’s big. I believe there is a size limit on how much this folder can grow, on Windows XP that size is 252 MB. if you want to see the settings for this folder click on Start then Control Panel then click on Internet Options and beneath Browsing History click on Settings:

temporary Internet Files

From this window you can change the settings on how the Temporary Internet Files behave, and as you can see, you also have the options to not cache anything, that means that every time you visit a website, a fresh copy of the web files will be downloaded onto your computer, this is not good for speeding reasons. most people have websites that they visit frequently, the caching feature speed up the loading process by not requesting a new fresh of copy of the web files, but instead uses the files already on the temporary Internet files, that’s why normally loading a website for the first time takes longer.

another issue I have noticed with the Temporary Internet files is that keeps the Anti-virus scan busy on your computer, especially when it has grown big. because it is such a dangerous folder the antivirus scan everything that get’s loaded to this folder, when the folder has too many files, the scan normally takes longer, thus degrading the performance on your system.

Dude, where is the Script?

OK. so the best way to clean the Temporary Internet files is by using a log off script. every time you shutdown your computer, the script will clean up the temporary Internet files, so it does not grow too big, and the antivirus does not spend too much time scanning it.  the script that does the job beautifully is this:

Const TEMPORARY_INTERNET_FILES = &H20&
dim intDepth
Set objShell = CreateObject(“Shell.Application”)
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
‘Clean User Temporary Intenet Files
Set objNameSpace = objShell.Namespace(TEMPORARY_INTERNET_FILES)
Set objFolderItem = objNameSpace.Self
set objFolder=objFSO.GetFolder(objFolderItem.Path)
intDepth=0
RemoveFolder objFolder
‘Clean User Temp Files
Const TemporaryFolder = 2
Set tempFolder = objFSO.GetSpecialFolder(TemporaryFolder)
RemoveFolder tempFolder
sub RemoveFolder(objFolder)
‘ Recursively remove files and folders
intDepth=intDepth+1
on error resume next
for each objFile in objFolder.Files
objFile.Delete true
next
Err.Clear
on error goto 0
for each objSubfolder in objFolder.SubFolders
RemoveFolder objSubFolder
next
intDepth=intDepth-1
if intDepth<>0 then’ Don’t delete top-level folder
on error resume next
objFolder.Delete true
err.Clear
on error goto 0
end if
end sub

I must add that I did not write this script, but I know much about scripting that I know what is doing. I don’t remember quite well where I found the script, but if someone wants to take credit for it, say it on the comments.

download the file attached

Clean-up Temporary Internet Files Script

once you download this files click on Start then Run and type gpedit.msc and click on OK. the Group Policy window should come up:

group policy

under the User Configuration option, expand the Windows Settings folder, then click on Scripts ( logon/Log off ) then on the right panel click on Log off to open up the properties:

log off properties

click on the Add tab. under the Script Name browse to the location where you downloaded the file attached above. leave blank for Script Parameters.

adding the script

click on Ok. click on OK on the log off window properties also. close out of group policy and restart your computer to see if the script is working. when you shutdown the computer it should say “Running log off script” after the computer restarts, check the temporary Internet files folder to see if its clean.

that’s it, you don’t have to worry about the Temporary Internet Files anymore (:)