Thursday, June 3, 2010

FSO- Delete Cookies

'Delete Cookies for all users in your local disk
'Enahnces the script performance before each run instance
'Usage of fso
'Admin rights requiredto access other users profile

'Type : 1
**********************************************************************

Set fso = CreateObject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder ("C:\Documents and Settings")
Dim delCookies
For Each oUserFolder In oFolder.SubFolders
If fso.FolderExists (oUserFolder.Path & "\Cookies") Then
Set oCookies = oUserFolder.SubFolders("Cookies")
Set oCookieFiles = oCookies.Files
iCount = oCookieFiles.Count
ReDim delCookies(iCount - 1)
i = 0
For each oFile in oCookieFiles
Set delCookies(i) = oFile
i = i + 1
Next
For i = Lbound(delCookies) to UBound(delCookies)
If delCookies(i).name <> "index.dat" Then
delCookies(i).delete
Set delCookies(i) = Nothing
End If
Next
End If
Next

Set oFolder = Nothing
Set fso = Nothing

**********************************************************************

Type 2 : Using WScript

**********************************************************************

set FSO = createobject("scripting.filesystemobject")
set oSHELL = createobject("wscript.shell")
strProfile = oShell.expandenvironmentstrings("C:\Documents and Settings\A032231")
set ieTemp = FSO.GetFolder(strProfile & "\Local Settings\Temp").files
set ieTempIntFiles = fso.GetFolder(strProfile & "\Local Settings\Temporary Internet Files").Files
set cookies = fso.GetFolder(strProfile & "\Cookies").files
call killFiles(ieTemp)
call killFiles(ieTempIntFiles)
call killFiles(cookies)

sub killFiles (Files)
for each obj in Files
set files = fso.getfile(obj)
If NOT files.name = "index.dat" then
obj.Delete (force)
End if
next
end sub

set FSO = nothing
set oShell = nothing
set userProfile = Nothing
set ieTempIntFiles = Nothing
set cookies = Nothing

**********************************************************************

** Happy Automating **

No comments: