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?
 
RubalJConnect With a Mentor Commented:
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
 
David LeeCommented:
Hi, Jackspiner.

How about inserting some code into Outlook that'll empty that folder each time Outlook exits?
0
All Courses

From novice to tech pro — start learning today.