Need VB that will empty OLK folder in Temporary Internet Files directory

We have an issue where users on our terminal servers need their OLK folders emptied on a periodic basis.  Is there a VB script I can use that will automatically empty it when a person logs on?
JackspinerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RubalJCommented:
You can try the following script and put it under start up folder os TS User's profile. It'll clean up all temp files whenever you login RDP.

'///////////////////////////////////////////////////////////////////////////////////
'///
'///   Temporary Files Cleanup Script (TempClean.vbs)
'///
'///
'///////////////////////////////////////////////////////////////////////////////////
Option Explicit
Dim FSO, wshShell
Dim bytesTotal, bytesRecovered, bytesLeft, foldersRemoved
Dim totalbytesTotal, totalbytesRecovered, totalbytesLeft, totalfoldersRemoved
Set FSO = CreateObject("Scripting.FileSystemObject")
Set wshShell = CreateObject("WScript.Shell")
If Not WScript.FullName = WScript.Path & "\cscript.exe" Then
   wshShell.Run WScript.Path & "\cscript.exe //NOLOGO " & Chr(34) & WScript.scriptFullName & Chr(34), 1, False
   WScript.Quit 0
End If
'///////////////////////////////////////////////////////////////////////////////////
'///
'///   User Definable Variables
'///
'///////////////////////////////////////////////////////////////////////////////////
Const DaysBeforeDelete = 30
Dim tempFolder, tempFolders(2)
tempFolders(0) = Replace(wshShell.Environment("System")("TEMP"), "%SystemRoot%", wshShell.Environment("Process")("SYSTEMROOT"), 1, -1, 1)
tempFolders(1) = FSO.BuildPath(FSO.GetSpecialFolder(0), "Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files")
tempFolders(2) = FSO.BuildPath(FSO.GetSpecialFolder(0), "Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files")
'///////////////////////////////////////////////////////////////////////////////////
'///////////////////////////////////////////////////////////////////////////////////
totalbytesTotal = 0
totalbytesRecovered = 0
totalbytesLeft = 0
totalfoldersRemoved = 0
For Each tempFolder In tempFolders
   bytesTotal = 0
   bytesRecovered = 0
   bytesLeft = 0
   foldersRemoved = 0
   WScript.Echo(tempFolder)
   CheckFolder(tempFolder)
   WScript.Echo(FormatNumber(bytesTotal/1024) & " KB total")
   WScript.Echo(FormatNumber(bytesRecovered/1024) & " KB recovered")
   WScript.Echo(FormatNumber(bytesLeft/1024) & " KB remaining")
   WScript.Echo(FormatNumber(foldersRemoved, 0) & " folders removed")
   WScript.Echo()
   totalbytesTotal = totalbytesTotal + bytesTotal
   totalbytesRecovered = totalbytesRecovered + bytesRecovered
   totalbytesLeft = totalbytesLeft + bytesLeft
   totalfoldersRemoved = totalfoldersRemoved + foldersRemoved
Next
WScript.Echo("TOTAL")
WScript.Echo(FormatNumber(totalbytesTotal/1024) & " KB total")
WScript.Echo(FormatNumber(totalbytesRecovered/1024) & " KB recovered")
WScript.Echo(FormatNumber(totalbytesLeft/1024) & " KB remaining")
WScript.Echo(FormatNumber(totalfoldersRemoved, 0) & " folders removed")
WScript.Echo()
Function CheckFolder(path)
   Dim FSO, curFolder, curSubFolders, curFiles, SubFolders, Folder, Files, File
   Set FSO = CreateObject("Scripting.FileSystemObject")
   Set curFolder = FSO.GetFolder(path)
   Set SubFolders = curFolder.SubFolders
   For Each Folder In SubFolders
      CheckFolder(FSO.BuildPath(path, Folder.Name))
      Set curFiles = Folder.Files
      Set curSubFolders = Folder.SubFolders
      If curFiles.Count = 0 And curSubFolders.Count = 0 Then
         foldersRemoved = foldersRemoved + 1
         Folder.Delete True
      End If
   Next
   Set Files = curFolder.Files
   For Each File In Files
      bytesTotal = bytesTotal + File.Size
      If DateDiff("d", File.DateLastAccessed, Now) > DaysBeforeDelete Then
         bytesRecovered = bytesRecovered + File.Size
         File.Delete True
      End If
   Next
   bytesLeft = curFolder.Size
End Function

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
David LeeCommented:
Hi, Jackspiner.

How about inserting some code into Outlook that'll empty that folder each time Outlook exits?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.