Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for delflash.vbs

(view source code of delflash.vbs as plain text)

  1. Option Explicit
  2.  
  3. Dim blnCScript, blnNoConfirm, blnQuiet, intDel
  4. Dim objFolder, objFSO, objSubFolder, wshShell
  5. Dim strFlashSettings, strFolder, strMsg
  6.  
  7. ' Create file system object
  8. Set objFSO = CreateObject( "Scripting.FileSystemObject" )
  9.  
  10. ' Display a help message, unless the /Q switch
  11. ' (Quiet mode) was used on the command line
  12. strMsg = objFSO.GetFileName( WScript.ScriptFullName ) _
  13.        & ",  Version 1.00" & vbCrLf _
  14.        & "Delete all ""Local Shared Objects"", " _
  15.        & "also known as ""Flash Cookies"", from the" & vbCrLf _
  16.        & "current user's profile" & vbCrLf & vbCrLf _
  17.        & "Usage:  " _
  18.        & objFSO.GetBaseName( WScript.ScriptFullName ) _
  19.        & "  [ /Q | /S ]" & vbCrLf & vbCrLf _
  20.        & "Where:  /Q    Quiet mode (NO prompts for confirmation, " _
  21.        & "NO results on screen)" & vbCrLf _
  22.        & "        /S    Summarize  (NO prompts for confirmation, " _
  23.        & "BUT results on screen)" & vbCrLf _
  24.        & "        (Default: BOTH prompts for confirmation " _
  25.        & "AND results on screen)" & vbCrLf & vbCrLf _
  26.        & "Notes:  It is recommended to run this script " _
  27.        & "without any command line switches" & vbCrLf _
  28.        & "        the first time (with the user ID for which it is " _
  29.        & "intended) to confirm" & vbCrLf _
  30.        & "        that the folders to be deleted " _
  31.        & "are the right ones." & vbCrLf _
  32.        & "        Though every effort has been made to " _
  33.        & "avoid failures, no guarantee can" & vbCrLf _
  34.        & "        be made for the proper functioning " _
  35.        & "of this script on your computer." & vbCrLf _
  36.        & "        Use this script entirely at your own risk!" & vbCrLf _
  37.        & "        To manage Flash Cooky settings, visit" _
  38.        & " http://www.macromedia.com/support" & vbCrLf _
  39.        & "        /documentation/en/flashplayer/help" _
  40.        & "/settings_manager02.html" & vbCrLf & vbCrLf _
  41.        & "Written by Rob van der Woude" & vbCrLf _
  42.        & "http://www.robvanderwoude.com"
  43. If WScript.Arguments.Unnamed.Count > 0 Then
  44. 	WScript.Echo strMsg
  45. 	Set objFSO = Nothing
  46. 	WScript.Quit 1
  47. End If
  48. With WScript.Arguments.Named
  49. 	If .Count > 1 Then
  50. 		WScript.Echo strMsg
  51. 		Set objFSO = Nothing
  52. 		WScript.Quit 1
  53. 	End If
  54. 	If .Count = 1 And Not .Exists("Q") And Not .Exists("s") Then
  55. 		WScript.Echo strMsg
  56. 		Set objFSO = Nothing
  57. 		WScript.Quit 1
  58. 	End If
  59. 	If .Exists("Q") Then
  60. 		blnQuiet = True
  61. 	Else
  62. 		blnQuiet = False
  63. 	End If
  64. 	If .Exists("S") Then
  65. 		blnNoConfirm = True
  66. 	Else
  67. 		blnNoConfirm = False
  68. 	End If
  69. End With
  70.  
  71. ' Determine the scripting engine
  72. If UCase( Right( WScript.FullName, 12 ) ) = "\CSCRIPT.EXE" Then
  73. 	blnCScript = True
  74. 	strMsg = strMsg & vbCrLf & vbCrLf & vbCrLf
  75. Else
  76. 	blnCScript = False
  77. End If
  78.  
  79. ' Display the help unless in Quiet Mode
  80. If Not blnQuiet Then WScript.Echo strMsg
  81.  
  82. ' Create scripting shell object
  83. Set wshShell = CreateObject( "WScript.Shell" )
  84.  
  85. ' Locate the Macromedia Flash settings folder in the current user's profile
  86. strFlashSettings = wshShell.ExpandEnvironmentStrings( "%UserProfile%" ) _
  87.                  & "\Application Data\Macromedia\Flash Player"
  88.  
  89. ' Delete all files and folders in the subfolder
  90. ' "#SharedObjects", but keep the subfolder itself
  91. strFolder = strFlashSettings & "\#SharedObjects"
  92. intDel    = DelTree( strFolder, False, blnNoConfirm )
  93.  
  94. ' Delete only subfolders, not files, of the subfolder
  95. ' "macromedia.com\support\flashplayer\sys"
  96. strFolder = strFlashSettings & "\macromedia.com\support\flashplayer\sys"
  97. Set objFolder = objFSO.GetFolder( strFolder )
  98. For Each objSubFolder In objFolder.SubFolders
  99. 	intDel = intDel + DelTree( objSubFolder.Path, True, blnNoConfirm )
  100. Next
  101.  
  102. ' Format message
  103. strMsg = "Results of " _
  104.        & objFSO.GetFileName( WScript.ScriptFullName ) _
  105.        & " run at " & Date & ", " & Time & ":" & vbCrLf
  106. If intDel = 1 Then
  107. 	strMsg = strMsg & "1 object deleted"
  108. Else
  109. 	strMsg = strMsg & intDel & " objects deleted"
  110. End If
  111.  
  112. ' Display message, unless /Q (Quiet mode) was specified on the command line
  113. If Not blnQuiet Then WScript.Echo strMsg
  114.  
  115. ' Release objects
  116. Set objFSO   = Nothing
  117. Set wshShell = Nothing
  118.  
  119.  
  120. Function ConfirmDelete( myFolder, blnIncludeRoot, blnSilent )
  121. 	' Abort if in Quiet Mode
  122. 	If blnQuiet Or blnSilent Then
  123. 		ConfirmDelete = True
  124. 		Exit Function
  125. 	End If
  126.  
  127. 	Dim intButtons, strPrompt, strTitle
  128.  
  129. 	' Format the prompt text to be displayed
  130. 	If blnIncludeRoot Then
  131. 		strPrompt  = "Delete folder """ _
  132. 		           & Replace( myFolder, """", "" ) _
  133. 		           & """ and all of its contents?"
  134. 	Else
  135. 		strPrompt  = "Delete the contents of folder """ _
  136. 		           & Replace( myFolder, """", "" ) & """?"
  137. 	End If
  138.  
  139. 	' Use StdIn and StdOut if we're running
  140. 	' in CSCRIPT, or use MsgBox otherwise
  141. 	If blnCScript Then
  142. 		WScript.StdOut.Write strPrompt & "(Y/N): "
  143. 		If UCase( WScript.StdIn.ReadLine( ) ) = "Y" Then
  144. 			ConfirmDelete = True
  145. 		Else
  146. 			ConfirmDelete = False
  147. 		End If
  148. 		WScript.StdOut.WriteBlankLines(1)
  149. 	Else
  150. 		intButtons = vbYesNo + vbDefaultButton2 + vbQuestion
  151. 		strTitle   = "Please confirm folder deletion"
  152. 		If MsgBox( strPrompt, intButtons, strTitle ) = vbYes Then
  153. 			ConfirmDelete = True
  154. 		Else
  155. 			ConfirmDelete = False
  156. 		End If
  157. 	End If
  158. End Function
  159.  
  160.  
  161. Function DelTree( myFolder, blnIncludeRoot, blnSilent )
  162. 	Dim intCount, objMyFile, objMyFolder, objMySubFolder
  163.  
  164. 	Const FORCE_DEL = True
  165.  
  166. 	' Reset counter of deleted files and folders
  167. 	intCount = 0
  168.  
  169. 	If objFSO.FolderExists( myFolder ) Then
  170. 		' Ask for confirmation unless in Quiet Mode
  171. 		If ConfirmDelete( myFolder, blnIncludeRoot, blnSilent ) Then
  172. 			' Create folder object
  173. 			Set objMyFolder = objFSO.GetFolder( myFolder )
  174. 			' First delete all files in the folder
  175. 			For Each objMyFile In objMyFolder.Files
  176. 				objMyFile.Delete FORCE_DEL
  177. 				intCount = intCount + 1
  178. 			Next
  179. 			' Next recurse through subfolders
  180. 			For Each objMySubFolder In objMyFolder.SubFolders
  181. 				intCount = intCount + DelTree( objMySubFolder.Path, True, True )
  182. 			Next
  183. 			' Finally remove the folder itself, unless second
  184. 			' argument to function (blnIncludeRoot) was False
  185. 			If blnIncludeRoot = True Then
  186. 				objMyFolder.Delete FORCE_DEL
  187. 				intCount = intCount + 1
  188. 			End If
  189. 			' Release folder object
  190. 			Set objMyFolder = Nothing
  191. 		Else
  192. 			WScript.Echo "Skipped folder """ _
  193. 			           & Replace( myFolder, """", "" ) & """"
  194. 		End If
  195. 	Else
  196. 		WScript.Echo "Error: Folder """ _
  197. 		           & Replace( myFolder, """", "" ) _
  198. 		           & """ not found!"
  199. 	End If
  200.  
  201. 	' Return number of deleted files and folders
  202. 	DelTree = intCount
  203. End Function
  204.  

page last modified: 2024-02-26; loaded in 0.0282 seconds