VBscript to delete cookies folder from profiles
VBscript to delete cookies folder from profiles PDF Print E-mail
Written by Administrator   
Wednesday, 10 June 2009 13:49

I have created a simple script to delete all the Cookies folders from my companys profiles.

The problem that I had was it took a long time for users to log in on Citrix due to the 1000's of cookies in some users profiles. I also use this script to delete the_RPCS folder once a month via a scheduled task.

This script can be modified to delete any folder.

'**********************************************************************
' Cookies.vbs
'
' Log will append to end of file
'
' Author......: Gary Smith, TheAwkward.Net

' Date Written: 10/06/2009
'
' Usage: c:\loctionofscript\> Cscript Cookies.vbs
'
' Notes: 
' To run script and delete files remember to REM line 38
'
'**********************************************************************

Option Explicit
Dim objFSO, objLog

Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Const DeleteReadOnly = True
Const FOR_APPENDING = 8
Const CREATE_FILE_IF_DOES_NOT_EXIST = True
DeleteFolderContent "\\ServerNameOrIpAddress\Staff$\Profiles"
objLog.Close

Sub DeleteFolderContent(strFolderName)
On Error Resume Next
Dim objFile, objFolder, colSubFolders, objSubFolder
If objFSO.FolderExists(strFolderName) Then
    WScript.Echo "Folder Exists"
    Set objFolder = objFSO.GetFolder(strFolderName)
    Set colSubfolders = objFolder.Subfolders
    For Each objSubfolder in colSubfolders
       ' The subFolder would be the Profile Name, and then you just
        ' use string concantenation to tack on the Cookies.
        If objFSO.FolderExist(objSubfolder.Path & "\Cookies") Then
             'unREM the line below to delete files.
             'objFSO.DeleteFolder(objSubfolder.Path & "\Cookies"), DeleteReadOnly
            WScript.Echo Now() & vbTab & "Deleting " & objSubfolder.Path & "\Cookies"
            LogIt Now() & vbTab & "Deleting " & objSubfolder.Path & "\Cookies" & vbTab & objSubFolder.DateLastModified
        Else
            WScript.Echo Now() & vbTab & "Folder Not Found: " & objSubfolder.Path & "\Cookies" & vbTab & "N\A"
            LogIt Now() & vbTab & "Folder Not Found: " & objSubfolder.Path & "\Cookies" & vbTab & "N\A"
        End If
    Next
End If
On Error GoTo 0
End Sub

Sub LogIt(strLine)
 If IsObject(objLog) Then
     objLog.WriteLine strLine
 Else
     Set objLog = objFSO.OpenTextFile("C:\DeleteCookies.log", FOR_APPENDING, CREATE_FILE_IF_DOES_NOT_EXIST)
     objLog.WriteLine  strLine
 End If
End Sub
 '
'**********************************************************************

Last Updated ( Wednesday, 10 June 2009 14:21 )
 
Joomla Templates by Joomlashack