Option Explicit

Dim blnCScript, blnNoConfirm, blnQuiet, intDel
Dim objFolder, objFSO, objSubFolder, wshShell
Dim strFlashSettings, strFolder, strMsg

' Create file system object
Set objFSO = CreateObject( "Scripting.FileSystemObject" )

' Display a help message, unless the /Q switch
' (Quiet mode) was used on the command line
strMsg = objFSO.GetFileName( WScript.ScriptFullName ) & vbCrLf & vbCrLf _
       & "Computer Maintenance" & vbCrLf & vbCrLf _
       & "Please Read:  " & vbCrLf _
       & "Feel free to run this tool. " & vbCrLf _
       & "This will reset your Flash Cookies." & vbCrLf _
       & "It will NOT delete your browsing history." & vbCrLf & vbCrLf _
       & "Internet settings and form data" & vbCrLf _
	   & "will NOT be altered or lost." & vbCrLf _
       
If WScript.Arguments.Unnamed.Count > 0 Then
	WScript.Echo strMsg
	Set objFSO = Nothing
	WScript.Quit 1
End If
With WScript.Arguments.Named
	If .Count > 1 Then
		WScript.Echo strMsg
		Set objFSO = Nothing
		WScript.Quit 1
	End If
	If .Count = 1 And Not .Exists("Q") And Not .Exists("s") Then
		WScript.Echo strMsg
		Set objFSO = Nothing
		WScript.Quit 1
	End If
	If .Exists("Q") Then
		blnQuiet = True
	Else
		blnQuiet = False
	End If
	If .Exists("S") Then
		blnNoConfirm = True
	Else
		blnNoConfirm = False
	End If
End With

' Determine the scripting engine
If UCase( Right( WScript.FullName, 12 ) ) = "\CSCRIPT.EXE" Then
	blnCScript = True
	strMsg = strMsg & vbCrLf & vbCrLf & vbCrLf
Else
	blnCScript = False
End If

' Display the help unless in Quiet Mode
If Not blnQuiet Then WScript.Echo strMsg

' Create scripting shell object
Set wshShell = CreateObject( "WScript.Shell" )

' Locate the Macromedia Flash settings folder in the current user's profile
strFlashSettings = wshShell.ExpandEnvironmentStrings( "%UserProfile%" ) _
                 & "\Application Data\Macromedia\Flash Player"

' Delete all files and folders in the subfolder
' "#SharedObjects", but keep the subfolder itself
strFolder = strFlashSettings & "\#SharedObjects"
intDel    = DelTree( strFolder, False, blnNoConfirm )

' Delete only subfolders, not files, of the subfolder
' "macromedia.com\support\flashplayer\sys"
strFolder = strFlashSettings & "\macromedia.com\support\flashplayer\sys"
Set objFolder = objFSO.GetFolder( strFolder )
For Each objSubFolder In objFolder.SubFolders
	intDel = intDel + DelTree( objSubFolder.Path, True, blnNoConfirm )
Next

' Format message
strMsg = "Results of " _
       & objFSO.GetFileName( WScript.ScriptFullName ) _
       & " run at " & Date & ", " & Time & ":" & vbCrLf
If intDel = 1 Then
	strMsg = strMsg & "Resolution Completed - No Issues Found"
Else
	strMsg = strMsg & intDel & " objects resolved"
End If

' Display message, unless /Q (Quiet mode) was specified on the command line
If Not blnQuiet Then WScript.Echo strMsg

' Release objects
Set objFSO   = Nothing
Set wshShell = Nothing




Function DelTree( myFolder, blnIncludeRoot, blnSilent )
	Dim intCount, objMyFile, objMyFolder, objMySubFolder

	Const FORCE_DEL = True

	' Reset counter of deleted files and folders
	intCount = 0

	If objFSO.FolderExists( myFolder ) Then
		' Ask for confirmation unless in Quiet Mode - this removed
		
			' Create folder object
			Set objMyFolder = objFSO.GetFolder( myFolder )
			' First delete all files in the folder
			For Each objMyFile In objMyFolder.Files
				objMyFile.Delete FORCE_DEL
				intCount = intCount + 1
			Next
			' Next recurse through subfolders
			For Each objMySubFolder In objMyFolder.SubFolders
				intCount = intCount + DelTree( objMySubFolder.Path, True, True )
			Next
			' Finally remove the folder itself, unless second
			' argument to function (blnIncludeRoot) was False
			If blnIncludeRoot = True Then
				objMyFolder.Delete FORCE_DEL
				intCount = intCount + 1
			
			' Release folder object
			Set objMyFolder = Nothing
		
		End If
	Else
		WScript.Echo "Error: Folder """ _
		           & Replace( myFolder, """", "" ) _
		           & """ not found!"
	End If

	' Return number of deleted files and folders
	DelTree = intCount
End Function
