Advertisement
Y0mOKJ3mZxAd

CATE version 4.7 change E

Sep 16th, 2017
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VBScript 12.76 KB | None | 0 0
  1. '
  2. ' Clean All Temp Etc.
  3. '
  4. ' version 4.7 change E
  5. '
  6. ' by Jonathan Brickman, a substantial rewrite and
  7. ' enhancement of a core originally written by David Barrett
  8. ' with contributions by Frank Voss
  9. ' http://notes.ponderworthy.com/?q=CATE
  10. '
  11. '
  12. ' last mod 2017-09-16
  13. ' IE browser clean-up number call-out
  14. '1    = Browsing History
  15. '2    = Cookies
  16. '4    = Temporary Internet Files
  17. '8    = Offline favorites and download history
  18. '16   = Form Data
  19. '32   = Passwords
  20. '64   = Phishing Filter Data
  21. '128  = Web page Recovery Data
  22. '256  = Do not Show GUI when running the cache clear
  23. '512  = Do not use Multi-threading for deletion
  24. '1024 = Valid only when browser is in private browsing mode
  25. '2048 = Tracking Data
  26. '4096 = Data stored by add-ons
  27. '8192 = Preserves Cached data for Favorite websites
  28. '8651 = Preserves Cached data for Favorite websites
  29. '
  30. ' added chrome and firefox clean-ups
  31. '
  32. ' last mod 2016-12-13
  33. ' Improved markers for failures.
  34. '
  35. ' last mod 2016-01-25
  36. ' Added second location for Temporary Internet Files
  37. ' Updated ForceCScript for Windows 8.1
  38. ' last mod 2015-12-26 " Clemente Reyes
  39. ' added force deletion to recycle bin ($recycler)
  40. ' not tested on win7
  41. ' last mod 2014-10-23
  42. ' Added deletion of *.pf in the Prefetch folder
  43. ' Added several more items
  44. ' Added clearing of profile WER data
  45. ' Added clearing of profile localappdata temp folders
  46. ' Fixed a few visual buglets
  47. ' Added clearing of Windows Error Reporting queue
  48. ' Added explicit search for system profiles
  49. ' Added clearing of Google Chrome cache
  50. ' Improved type setting for free space reports
  51. ' Added report as to how much space freed
  52. ' Added usability as SYSTEM user under Windows 7 et al.
  53. ' Added item ticks (comma for files, slash for subfolders)
  54. '
  55. ' Core originally written by David Barrett
  56. ' Copyright 2009
  57. ' http://www.cedit.biz/
  58. ' This script is licensed under the Creative Commons
  59. ' Attribution 2.5 Licence
  60. ' http://creativecommons.org/licenses/by/2.5/
  61. '
  62. ' You are free to use it for both personal and
  63. ' commercial purposes, so long as full attribution
  64. ' is given to the author (David Barrett).
  65. '
  66. ' This notice must not be removed
  67. '
  68. '
  69.  
  70. Function ForceCScript()
  71. On Error Resume Next
  72. WScript.StdErr.Write(Chr(7))
  73. If Err.Number <> 0 Then
  74.     Err.Clear
  75.     On Error GoTo 0
  76.     set WshSh=WScript.CreateObject("WScript.Shell")
  77.     sh=WshSh.ExpandEnvironmentStrings("%COMSPEC%")
  78.     If InStr(sh,"%") = 1 Then sh="cmd.exe"
  79.     WshSh.Run(sh&" /K Title Clean All Temp Etc. v4.7 chg. E |MODE 90,7 | color 0e &cscript.exe //nologo """ _
  80.     &WScript.ScriptFullName&"""")
  81.     WScript.Quit()
  82. End If
  83. End Function
  84.  
  85. call ForceCScript()
  86.  
  87. dim objWSH, objFSO, sysDrv, initialFreeSpace, strComputer, objRegistry
  88. dim strKeyPath, objSubKey, arrSubkeys, strValueName, sProfile
  89. dim sTemp, sTmp, sWindows, sLocalAppData, sProgramData, sWER, sDotNetItem
  90. dim profileQty, profileCount
  91.  
  92. wscript.echo "Clean All Temp v4.7 change E"
  93. wscript.echo ""
  94. wscript.echo "originally by David Barrett"
  95. wscript.echo "updated and modded substantially by Jonathan E. Brickman"
  96. wscript.echo ""
  97. wscript.echo "Cleans all profiles' temp and IE cache folders"
  98. wscript.echo "A whole subfolder deletion is indicated by \"
  99. wscript.echo "A file deletion is indicated by ,"
  100. wscript.echo "A whole subfolder deletion failure is indicated by X"
  101. wscript.echo "A file deletion failure is indicated by x"
  102. wscript.echo ""
  103.  
  104. set objFSO = CreateObject("Scripting.FileSystemObject")
  105. set objWSH = CreateObject("WScript.Shell")
  106. set sysDrv = objFSO.GetDrive(objFSO.GetDriveName(objWSH.ExpandEnvironmentStrings("%SystemDrive%")))
  107. set  sa = CreateObject("Shell.Application")
  108. Set items = sa.Namespace(10).Items()
  109.  
  110. sTemp = objWSH.ExpandEnvironmentStrings("%TEMP%")
  111. sTmp = objWSH.ExpandEnvironmentStrings("%TMP%")
  112. sWindows = objWSH.ExpandEnvironmentStrings("%SystemRoot%")
  113. sLocalAppData = objWSH.ExpandEnvironmentStrings("%LOCALAPPDATA%")
  114. sProgramData = objWSH.ExpandEnvironmentStrings("%ProgramData%")
  115. If sProgramData <> "" Then
  116.     sWER = objWSH.ExpandEnvironmentStrings("%ProgramData%") & "\Microsoft\Windows\WER\ReportQueue"
  117. Else
  118.     sWER = ""
  119. End If
  120. UserName = CreateObject("WScript.Network").UserName
  121. RootFolder = "C:\Users\" & UserName & "\AppData\Local\Google\Chrome\User Data\"
  122. 'Firefox local path
  123. FFRootFolder = "C:\Users\" & UserName & "\AppData\Local\Mozilla\Firefox\Profiles"
  124. 'Firefox roaming path
  125. FFroamFolder = "C:\Users\" & UserName & "\AppData\Roaming\Mozilla\Firefox\Profiles"
  126.  
  127. ' Get current free space on system drive
  128. initialFreeSpace = CDbl(sysDrv.FreeSpace)
  129.  
  130. Const HKEY_LOCAL_MACHINE = &H80000002
  131.  
  132. strComputer = "."
  133.  
  134. Set objRegistry=GetObject("winmgmts:\\" & _
  135.     strComputer & "\root\default:StdRegProv")
  136.  
  137. strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
  138. objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
  139. profileQty = uBound(arrSubkeys) + 1
  140. profileCount = 1
  141.  
  142. For Each objSubkey In arrSubkeys
  143.  
  144.     strValueName = "ProfileImagePath"
  145.     strSubPath = strKeyPath & "\" & objSubkey
  146.     objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,strSubPath,strValueName,sProfile
  147.  
  148.     wscript.echo "Cleaning profile folder " & profileCount & " of " & profileQty & " : " & sProfile
  149.  
  150.     DeleteFolderContents sProfile & "\Local Settings\Temp"
  151.  
  152.     DeleteFolderContents sProfile & "\Local Settings\Temporary Internet Files"
  153.  
  154.     DeleteFolderContents sProfile & "\AppData\Local\Microsoft\Windows\Temporary Internet Files"
  155.  
  156.     DeleteFolderContents sProfile & "\AppData\Local\Google\Chrome\User Data\Default\Cache"
  157.  
  158.     ' Windows 8 and 8.1
  159.     DeleteFolderContents sProfile & "\AppData\Local\Microsoft\Windows\INetCache\IE"
  160.  
  161.     ' Windows 10
  162.     DeleteFolderContents sProfile & "\AppData\Local\Microsoft\Windows\INetCache\Low\Content.IE5"
  163.     DeleteFolderContents sProfile & "\AppData\Local\Microsoft\Windows\INetCache\Low\Flash"
  164.     DeleteFolderContents sProfile & "\AppData\Local\Microsoft\Windows\INetCache\Content.Outlook"
  165.  
  166.     If objFSO.FolderExists(sProfile & "\AppData\Local\Temp") Then
  167.         DeleteFolderContents sProfile & "\AppData\Local\Temp"
  168.         objFSO.CreateFolder(sProfile & "\AppData\Local\Temp\Low")
  169.         objWSH.Run "icacls " & sProfile & "\Appdata\Local\Temp\Low /setintegritylevel low", 0
  170.     End If
  171.  
  172.     DeleteFolderContents sProfile & "\Application Data\Local\Microsoft\Windows\WER"
  173.  
  174.     DeleteFolderContents sProfile & "\Application Data\Adobe\Flash Player\AssetCache"
  175.  
  176.     DeleteFolderContents sProfile & "\Application Data\Sun\Java\Deployment\cache"
  177.  
  178.     DeleteFolderContents sProfile & "\Application Data\Microsoft\CryptnetUrlCache"
  179.  
  180.     profileCount = profileCount + 1
  181.  
  182. Next
  183.  
  184. ' Now empty certain folders in %SystemRoot%
  185.  
  186. wscript.echo "Processing folder: " & sWindows & "\Temp"
  187. DeleteFolderContents sWindows & "\Temp"
  188.  
  189. wscript.echo "Processing folder: " & sWindows & "\system32\wbem\Logs"
  190. DeleteFolderContents sWindows & "\system32\wbem\Logs"
  191.  
  192. wscript.echo "Processing folder: " & sWindows & "\Debug"
  193. DeleteFolderContents sWindows & "\Debug"
  194.  
  195. wscript.echo "Processing folder: " & sWindows & "\PCHEALTH\ERRORREP\UserDumps"
  196. DeleteFolderContents sWindows & "\PCHEALTH\ERRORREP\UserDumps"
  197.  
  198. ' And ditto the system-wide Windows Error Reporting queue, if it exists.
  199. If sWER <> "" Then
  200.     wscript.echo "Processing folder: " & sWER
  201.     DeleteFolderContents sWER
  202. End If
  203.  
  204. ' Delete all log files.
  205. wscript.echo "Processing folder: " & sWindows & "\system32\Logfiles"
  206. DeleteSubfolderFiles sWindows & "\system32\Logfiles"
  207.  
  208. ' Delete Trash Bin
  209. wscript.echo "Processing folder: " & sysDrv & "\$Recycle.Bin"
  210. DeleteFolderContents sysDrv & "\$Recycle.Bin"
  211.  
  212. ' Delete all *.pf in Prefetch
  213. wscript.echo "Deleting " & sWindows & "\Prefetch\*.pf"
  214. objWsh.run "CMD.EXE /C DEL """ & sWindows & "\Prefetch\*.pf"" > NUL", 0, true
  215.  
  216. ' Avoid crashing if elevation is needed to delete a file.
  217. On Error Resume Next
  218. For Each item in items
  219.     If objFSO.FileExists(item.Path) Then
  220.         objFSO.DeleteFile item.Path, True
  221.     Else
  222.         objFSO.DeleteFolder item.Path, True
  223.     End If
  224. Next
  225.  
  226. wscript.Echo ""
  227. WScript.echo "Freed " & CLng( CDbl(CDbl(sysDrv.FreeSpace) - CDbl(initialFreeSpace))/CDbl(1024*1024)) & " megabytes."
  228.  
  229. wscript.Echo ""
  230.  
  231. 'To clear temporary Internet files
  232. wscript.echo "Deleting Temp Files"
  233. objWSH.run "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8"
  234.  
  235. 'To clear browsing cookies
  236. wscript.echo "Deleting Cookies"
  237. objWSH.run "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2"
  238.  
  239. 'To Clear Browsing History
  240. wscript.echo "Deleting Browser History"
  241. objWSH.run "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1"
  242.  
  243. 'To Clear passwords
  244. wscript.echo "Deleting saved passwords"
  245. objWSH.run "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32"
  246.  
  247. 'To Clear/delete all
  248. wscript.echo "Deleting no GUI all"
  249. objWSH.run "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255"
  250.  
  251. 'To Delete All – “Also delete files and settings stored by add-ons”
  252. objWSH.run "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351"
  253.  
  254. wscript.Echo ""
  255. wscript.echo "Cleaning Chrome browser"
  256. ProcessTerminate "chrome.exe"
  257. DeleteFileFromFolder RootFolder
  258.  
  259. wscript.Echo ""
  260. wscript.echo "Cleaning Firefox browser"
  261. ProcessTerminate "firefox.exe"
  262. DeleteFileFromFolder FFRootFolder
  263. DeleteFileFromFolder FFroamFolder
  264.  
  265. wscript.Echo ""
  266. WScript.echo "Requires Computer to either shutdown or restart upon User Login."
  267.  
  268. Set sa = Nothing
  269. Set items = Nothing
  270. Set sysDrv = Nothing
  271. Set objWsH = Nothing
  272. Set objFSO = Nothing
  273. Set objRegistry = Nothing
  274.  
  275. ' ---------------------- Subroutines -------------------
  276.  
  277. sub DeleteFolderContents(strFolder)
  278.     ' Deletes all files and folders within the given folder
  279.    dim objFolder, objFile, objSubFolder, doCRLF
  280.     on error resume next
  281.    
  282.     ' Just exit if the named folder doesn't exist on this system
  283.    If Not objFSO.FolderExists(strFolder) Then
  284.     Exit Sub
  285.     End If
  286.  
  287.     doCRLF = 0
  288.     set objFolder=objFSO.GetFolder(strFolder)
  289.  
  290.     if Err.Number<>0 then
  291.         Err.Clear
  292.     set objFolder = Nothing
  293.         Exit Sub ' Couldn't get a handle to the folder, so can't do anything
  294.    end if
  295.     for each objSubFolder in objFolder.SubFolders
  296.         objSubFolder.Delete true
  297.         if Err.Number<>0 then
  298.         'Could not delete whole folder
  299.         wscript.stdout.write "X"
  300.             'Try recursive, delete everything inside,
  301.         'ensuring as complete an overall result as possible
  302.         'do NOT do CRLF after this sub iteration ends
  303.             doCRLF = 0
  304.             Err.Clear
  305.             DeleteFolderContents(strFolder & "\" & objSubFolder.Name)
  306.     else
  307.         wscript.stdout.write "\"
  308.         doCRLF = 1
  309.         end if
  310.     next
  311.     for each objFile in ObjFolder.Files
  312.         objFile.Delete true
  313.         if Err.Number<>0 then
  314.         wscript.stdout.write "x"
  315.             doCRLF = 1
  316.         Err.Clear ' In case we couldn't delete a file
  317.     else
  318.         wscript.stdout.write ","
  319.             doCRLF = 1
  320.     end if
  321.     next
  322.  
  323.     Set objFolder = Nothing
  324.  
  325.     if doCRLF > 0 then
  326.     wscript.stdout.write vbCRLF
  327.     end if
  328. end sub
  329.  
  330. sub DeleteSubfolderFiles(strFolder)
  331.     ' Deletes all files only, within subfolders of the current folder
  332.    dim objFolder, objFile, objSubFolder, doCRLF
  333.     on error resume next
  334.  
  335.     doCRLF = 0
  336.  
  337.     set objFolder=objFSO.GetFolder(strFolder)
  338.  
  339.     if Err.Number<>0 then
  340.         Err.Clear
  341.     set objFolder = Nothing
  342.         Exit Sub ' Couldn't get a handle to the folder, so can't do anything
  343.    end if
  344.  
  345.     for each objSubFolder in objFolder.SubFolders
  346.     for each objFile in objSubFolder.Files
  347.         objFile.Delete true
  348.                 if Err.Number<>0 then
  349.             wscript.stdout.write "x"
  350.             doCRLF = 1
  351.             Err.Clear ' In case we couldn't delete a file
  352.         else
  353.             wscript.stdout.write ","
  354.                 doCRLF = 1
  355.         end if
  356.     next
  357.     next
  358.  
  359.     Set objFolder = Nothing
  360.  
  361.     if doCRLF > 0 then
  362.     wscript.stdout.write vbCRLF
  363.     end if
  364. end sub
  365.  
  366. 'Chrome Subroutine
  367. Sub DeleteFileFromFolder(Path)
  368.     For Each File In objFSO.GetFolder(Path).Files
  369.         DeleteAllow File
  370.     Next
  371.     For Each File In objFSO.GetFolder(Path).SubFolders
  372.         DeleteFileFromFolder File.Path
  373.     Next
  374. End Sub
  375.  
  376. Sub DeleteAllow(File)
  377.     'Bookmarks remain same
  378.    If NOT(StrComp(Left(File.Name, 9), "Bookmarks", vbTextCompare)) = 0 Then
  379.         Wscript.Echo File.Path + " Deleted"    
  380.         On Error Resume Next
  381.         objFSO.DeleteFile File.Path, True
  382.     End If
  383. End Sub
  384.  
  385. Sub ProcessTerminate(Process)
  386.     Const StrComputer = "."
  387.     Dim WshShell, ObjWMIService, ProcessList, ObjProcess
  388.     Set WshShell = CreateObject("WScript.Shell")
  389.     Set ObjWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & StrComputer & "\root\cimv2")
  390.  
  391.     Set ProcessList = ObjWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = '" & Process & "'")
  392.     For Each ObjProcess in ProcessList
  393.         On Error Resume Next
  394.         ObjProcess.Terminate
  395.         Wscript.Echo "Process Terminated, ProcessId=" & ObjProcess.ProcessId & " (" & ObjProcess.Name & ")"
  396.     Next
  397. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement