Search code examples
windowsvbscriptscheduled-tasksbatch-processingtemporary-files

Stop a VBS Script filling up temp Internet files


I have a .vbs script that is creating a lot of temp Internet files fast. How can I reduce this? Its a Windows Server 2016 box

I have tried placing a limit on this using IE > Tools > temp Intranet files.... however this does not work. I suspect its because the actual browser is not being opened. The .vbs file is triggered by a Windows Scheduled Task on the hour. Its connects to an XML source using the HTTP protocol like so:

Set objxml = CreateObject("Msxml2.DOMDocument")
objxml.setProperty "SelectionLanguage", "XPath"
objXML.async =  False
objXML.Load url 

Then it traverses the XML, inserts the data into a DB and then finishes. The outcome of this is around 40MB of files in this location every hour:

C:\Users\[theUser]\AppData\Local\Microsoft\Windows\INetCache\IE

As I said above. I have logged into the server as [theUser] and set the upper limit to 200MB but it does not obey this. How can I stop this process blowing out the temp Internet files location for [theUser]?

Edited: The accepted solution is better if you are not behind a proxy IMO. I elected to run the WST with high prvelleges and do this:

 call dumpAllFilesInFolder("C:\Users\[theUser]\AppData\Local\Microsoft\Windows\INetCache\IE")
 function dumpAllFilesInFolder(theFullPath)
    dim objFS, curFile, objFolder, objFiles
    Set objFS = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFS.GetFolder(theFullPath) 
    Set objFiles = objFolder.Files
    For each curFile in objFiles
        objFS.DeleteFile(curFile)
    Next
end function

Solution

  • Unless otherwise specified DOMDocument uses WinINET API which was developed for user interactive applications primarily. The cache files that cause the problem you are experiencing are created due to WinINET's cache behavior, in short: everything that can be cached must be cached.

    As an alternative you can force your DomDocument object to use WinHTTP by setting ServerHTTPRequest property to True. Unlike WinINET, WinHTTP was designed for server-side applications, so nothing will be cached. Seems better for your environment.

    Set objxml = CreateObject("Msxml2.DOMDocument")
    objxml.setProperty "SelectionLanguage", "XPath"
    objxml.setProperty "ServerHTTPRequest", True
    objXML.async = False
    objXML.Load url 
    

    Related Links