Script to delete specific IE cookies

Posted on Updated on

An old script to share :-) It will delete IE cookies specified in variable CookieName

'==========================================================================
' NAME: DeleteIeCookiesCraigslist
' AUTHOR: Nick Moseley , https://t3chn1ck.wordpress.com
' DATE  : 8/11/2011
'
' COMMENT: Deletes the cookies specified in variable CookieName
'==========================================================================
Option Explicit

Const CookieName = "EnterCookieName"
Const ForAppending = 8
Const HKLM = &H80000002
Const EnableLogging = True

' Basic objects
Dim oReg, oShell, oFSO, iCountFiles
Set oReg = GetObject("winmgmts:\\.\root\default:StdRegProv")
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject ("Scripting.FileSystemObject")
iCountFiles = 0

'==========================================================================
' Begin log file etnries
'==========================================================================
If EnableLogging = True Then 
	Dim oVersionLog
	If Not oFSO.FileExists("C:\Windows\Temp\DeleteIeCookies.log") Then
		oFSO.CreateTextFile "C:\Windows\Temp\DeleteIeCookies.log"
	End If
	Set oVersionLog = oFSO.OpenTextFile ("C:\Windows\Temp\DeleteIeCookies.log", ForAppending, True)
	
	oVersionLog.WriteLine "Delete Craigslist cookies"
	oVersionLog.WriteLine "  => Began at " & Date & " " & Time
End If
'==========================================================================

' Get list of folders in C:\Users
Dim oUserFolders, oFolder, colFiles, oUserCookieFolder, oFile
Set oUserFolders = oFSO.GetFolder("C:\Users") 

For Each oFolder In oUserFolders.subfolders 
	DeleteFile ("C:\Users\" & oFolder.name & "\AppData\Roaming\Microsoft\Windows\Cookies") 
	DeleteFile ("C:\Users\" & oFolder.name & "\AppData\Roaming\Microsoft\Windows\Cookies\Low") 
Next 

' End logging
If EnableLogging = True Then 
	oVersionLog.WriteLine "  => Total number of deleted cookies: " & iCountFiles
	oVersionLog.WriteLine "  => Completed at " & Date & " " & Time
	oVersionLog.Close
End If

WScript.Quit

Sub DeleteFile (sFolderPath)
	If oFSO.FolderExists (sFolderPath) Then
		Set oUserCookieFolder = oFSO.GetFolder(sFolderPath)
		Set colFiles = oUserCookieFolder.Files
		For Each oFile In colFiles
			If InStr (oFile.Name, CookieName) Then 
				If EnableLogging = True Then
					oVersionLog.WriteLine "  => Deleted " & sFolderPath & "\" & oFile.Name
				Else
					WScript.Echo sFolderPath & "\" & oFile.Name
				End If
				oFSO.DeleteFile sFolderPath & "\" & oFile.Name
				iCountFiles = iCountFiles + 1
			End If
		Next 
	End If	
End Sub
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s