Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '
- ' Clean All Temp Etc.
- '
- ' version 4.7 change E
- '
- ' by Jonathan Brickman, a substantial rewrite and
- ' enhancement of a core originally written by David Barrett
- ' with contributions by Frank Voss
- ' http://notes.ponderworthy.com/?q=CATE
- '
- '
- ' last mod 2017-09-16
- ' IE browser clean-up number call-out
- '1 = Browsing History
- '2 = Cookies
- '4 = Temporary Internet Files
- '8 = Offline favorites and download history
- '16 = Form Data
- '32 = Passwords
- '64 = Phishing Filter Data
- '128 = Web page Recovery Data
- '256 = Do not Show GUI when running the cache clear
- '512 = Do not use Multi-threading for deletion
- '1024 = Valid only when browser is in private browsing mode
- '2048 = Tracking Data
- '4096 = Data stored by add-ons
- '8192 = Preserves Cached data for Favorite websites
- '8651 = Preserves Cached data for Favorite websites
- '
- ' added chrome and firefox clean-ups
- '
- ' last mod 2016-12-13
- ' Improved markers for failures.
- '
- ' last mod 2016-01-25
- ' Added second location for Temporary Internet Files
- ' Updated ForceCScript for Windows 8.1
- ' last mod 2015-12-26 " Clemente Reyes
- ' added force deletion to recycle bin ($recycler)
- ' not tested on win7
- ' last mod 2014-10-23
- ' Added deletion of *.pf in the Prefetch folder
- ' Added several more items
- ' Added clearing of profile WER data
- ' Added clearing of profile localappdata temp folders
- ' Fixed a few visual buglets
- ' Added clearing of Windows Error Reporting queue
- ' Added explicit search for system profiles
- ' Added clearing of Google Chrome cache
- ' Improved type setting for free space reports
- ' Added report as to how much space freed
- ' Added usability as SYSTEM user under Windows 7 et al.
- ' Added item ticks (comma for files, slash for subfolders)
- '
- ' Core originally written by David Barrett
- ' Copyright 2009
- ' http://www.cedit.biz/
- ' This script is licensed under the Creative Commons
- ' Attribution 2.5 Licence
- ' http://creativecommons.org/licenses/by/2.5/
- '
- ' You are free to use it for both personal and
- ' commercial purposes, so long as full attribution
- ' is given to the author (David Barrett).
- '
- ' This notice must not be removed
- '
- '
- Function ForceCScript()
- On Error Resume Next
- WScript.StdErr.Write(Chr(7))
- If Err.Number <> 0 Then
- Err.Clear
- On Error GoTo 0
- set WshSh=WScript.CreateObject("WScript.Shell")
- sh=WshSh.ExpandEnvironmentStrings("%COMSPEC%")
- If InStr(sh,"%") = 1 Then sh="cmd.exe"
- WshSh.Run(sh&" /K Title Clean All Temp Etc. v4.7 chg. E |MODE 90,7 | color 0e &cscript.exe //nologo """ _
- &WScript.ScriptFullName&"""")
- WScript.Quit()
- End If
- End Function
- call ForceCScript()
- dim objWSH, objFSO, sysDrv, initialFreeSpace, strComputer, objRegistry
- dim strKeyPath, objSubKey, arrSubkeys, strValueName, sProfile
- dim sTemp, sTmp, sWindows, sLocalAppData, sProgramData, sWER, sDotNetItem
- dim profileQty, profileCount
- wscript.echo "Clean All Temp v4.7 change E"
- wscript.echo ""
- wscript.echo "originally by David Barrett"
- wscript.echo "updated and modded substantially by Jonathan E. Brickman"
- wscript.echo ""
- wscript.echo "Cleans all profiles' temp and IE cache folders"
- wscript.echo "A whole subfolder deletion is indicated by \"
- wscript.echo "A file deletion is indicated by ,"
- wscript.echo "A whole subfolder deletion failure is indicated by X"
- wscript.echo "A file deletion failure is indicated by x"
- wscript.echo ""
- set objFSO = CreateObject("Scripting.FileSystemObject")
- set objWSH = CreateObject("WScript.Shell")
- set sysDrv = objFSO.GetDrive(objFSO.GetDriveName(objWSH.ExpandEnvironmentStrings("%SystemDrive%")))
- set sa = CreateObject("Shell.Application")
- Set items = sa.Namespace(10).Items()
- sTemp = objWSH.ExpandEnvironmentStrings("%TEMP%")
- sTmp = objWSH.ExpandEnvironmentStrings("%TMP%")
- sWindows = objWSH.ExpandEnvironmentStrings("%SystemRoot%")
- sLocalAppData = objWSH.ExpandEnvironmentStrings("%LOCALAPPDATA%")
- sProgramData = objWSH.ExpandEnvironmentStrings("%ProgramData%")
- If sProgramData <> "" Then
- sWER = objWSH.ExpandEnvironmentStrings("%ProgramData%") & "\Microsoft\Windows\WER\ReportQueue"
- Else
- sWER = ""
- End If
- UserName = CreateObject("WScript.Network").UserName
- RootFolder = "C:\Users\" & UserName & "\AppData\Local\Google\Chrome\User Data\"
- 'Firefox local path
- FFRootFolder = "C:\Users\" & UserName & "\AppData\Local\Mozilla\Firefox\Profiles"
- 'Firefox roaming path
- FFroamFolder = "C:\Users\" & UserName & "\AppData\Roaming\Mozilla\Firefox\Profiles"
- ' Get current free space on system drive
- initialFreeSpace = CDbl(sysDrv.FreeSpace)
- Const HKEY_LOCAL_MACHINE = &H80000002
- strComputer = "."
- Set objRegistry=GetObject("winmgmts:\\" & _
- strComputer & "\root\default:StdRegProv")
- strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
- objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
- profileQty = uBound(arrSubkeys) + 1
- profileCount = 1
- For Each objSubkey In arrSubkeys
- strValueName = "ProfileImagePath"
- strSubPath = strKeyPath & "\" & objSubkey
- objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,strSubPath,strValueName,sProfile
- wscript.echo "Cleaning profile folder " & profileCount & " of " & profileQty & " : " & sProfile
- DeleteFolderContents sProfile & "\Local Settings\Temp"
- DeleteFolderContents sProfile & "\Local Settings\Temporary Internet Files"
- DeleteFolderContents sProfile & "\AppData\Local\Microsoft\Windows\Temporary Internet Files"
- DeleteFolderContents sProfile & "\AppData\Local\Google\Chrome\User Data\Default\Cache"
- ' Windows 8 and 8.1
- DeleteFolderContents sProfile & "\AppData\Local\Microsoft\Windows\INetCache\IE"
- ' Windows 10
- DeleteFolderContents sProfile & "\AppData\Local\Microsoft\Windows\INetCache\Low\Content.IE5"
- DeleteFolderContents sProfile & "\AppData\Local\Microsoft\Windows\INetCache\Low\Flash"
- DeleteFolderContents sProfile & "\AppData\Local\Microsoft\Windows\INetCache\Content.Outlook"
- If objFSO.FolderExists(sProfile & "\AppData\Local\Temp") Then
- DeleteFolderContents sProfile & "\AppData\Local\Temp"
- objFSO.CreateFolder(sProfile & "\AppData\Local\Temp\Low")
- objWSH.Run "icacls " & sProfile & "\Appdata\Local\Temp\Low /setintegritylevel low", 0
- End If
- DeleteFolderContents sProfile & "\Application Data\Local\Microsoft\Windows\WER"
- DeleteFolderContents sProfile & "\Application Data\Adobe\Flash Player\AssetCache"
- DeleteFolderContents sProfile & "\Application Data\Sun\Java\Deployment\cache"
- DeleteFolderContents sProfile & "\Application Data\Microsoft\CryptnetUrlCache"
- profileCount = profileCount + 1
- Next
- ' Now empty certain folders in %SystemRoot%
- wscript.echo "Processing folder: " & sWindows & "\Temp"
- DeleteFolderContents sWindows & "\Temp"
- wscript.echo "Processing folder: " & sWindows & "\system32\wbem\Logs"
- DeleteFolderContents sWindows & "\system32\wbem\Logs"
- wscript.echo "Processing folder: " & sWindows & "\Debug"
- DeleteFolderContents sWindows & "\Debug"
- wscript.echo "Processing folder: " & sWindows & "\PCHEALTH\ERRORREP\UserDumps"
- DeleteFolderContents sWindows & "\PCHEALTH\ERRORREP\UserDumps"
- ' And ditto the system-wide Windows Error Reporting queue, if it exists.
- If sWER <> "" Then
- wscript.echo "Processing folder: " & sWER
- DeleteFolderContents sWER
- End If
- ' Delete all log files.
- wscript.echo "Processing folder: " & sWindows & "\system32\Logfiles"
- DeleteSubfolderFiles sWindows & "\system32\Logfiles"
- ' Delete Trash Bin
- wscript.echo "Processing folder: " & sysDrv & "\$Recycle.Bin"
- DeleteFolderContents sysDrv & "\$Recycle.Bin"
- ' Delete all *.pf in Prefetch
- wscript.echo "Deleting " & sWindows & "\Prefetch\*.pf"
- objWsh.run "CMD.EXE /C DEL """ & sWindows & "\Prefetch\*.pf"" > NUL", 0, true
- ' Avoid crashing if elevation is needed to delete a file.
- On Error Resume Next
- For Each item in items
- If objFSO.FileExists(item.Path) Then
- objFSO.DeleteFile item.Path, True
- Else
- objFSO.DeleteFolder item.Path, True
- End If
- Next
- wscript.Echo ""
- WScript.echo "Freed " & CLng( CDbl(CDbl(sysDrv.FreeSpace) - CDbl(initialFreeSpace))/CDbl(1024*1024)) & " megabytes."
- wscript.Echo ""
- 'To clear temporary Internet files
- wscript.echo "Deleting Temp Files"
- objWSH.run "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8"
- 'To clear browsing cookies
- wscript.echo "Deleting Cookies"
- objWSH.run "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2"
- 'To Clear Browsing History
- wscript.echo "Deleting Browser History"
- objWSH.run "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1"
- 'To Clear passwords
- wscript.echo "Deleting saved passwords"
- objWSH.run "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32"
- 'To Clear/delete all
- wscript.echo "Deleting no GUI all"
- objWSH.run "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255"
- 'To Delete All – “Also delete files and settings stored by add-ons”
- objWSH.run "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351"
- wscript.Echo ""
- wscript.echo "Cleaning Chrome browser"
- ProcessTerminate "chrome.exe"
- DeleteFileFromFolder RootFolder
- wscript.Echo ""
- wscript.echo "Cleaning Firefox browser"
- ProcessTerminate "firefox.exe"
- DeleteFileFromFolder FFRootFolder
- DeleteFileFromFolder FFroamFolder
- wscript.Echo ""
- WScript.echo "Requires Computer to either shutdown or restart upon User Login."
- Set sa = Nothing
- Set items = Nothing
- Set sysDrv = Nothing
- Set objWsH = Nothing
- Set objFSO = Nothing
- Set objRegistry = Nothing
- ' ---------------------- Subroutines -------------------
- sub DeleteFolderContents(strFolder)
- ' Deletes all files and folders within the given folder
- dim objFolder, objFile, objSubFolder, doCRLF
- on error resume next
- ' Just exit if the named folder doesn't exist on this system
- If Not objFSO.FolderExists(strFolder) Then
- Exit Sub
- End If
- doCRLF = 0
- set objFolder=objFSO.GetFolder(strFolder)
- if Err.Number<>0 then
- Err.Clear
- set objFolder = Nothing
- Exit Sub ' Couldn't get a handle to the folder, so can't do anything
- end if
- for each objSubFolder in objFolder.SubFolders
- objSubFolder.Delete true
- if Err.Number<>0 then
- 'Could not delete whole folder
- wscript.stdout.write "X"
- 'Try recursive, delete everything inside,
- 'ensuring as complete an overall result as possible
- 'do NOT do CRLF after this sub iteration ends
- doCRLF = 0
- Err.Clear
- DeleteFolderContents(strFolder & "\" & objSubFolder.Name)
- else
- wscript.stdout.write "\"
- doCRLF = 1
- end if
- next
- for each objFile in ObjFolder.Files
- objFile.Delete true
- if Err.Number<>0 then
- wscript.stdout.write "x"
- doCRLF = 1
- Err.Clear ' In case we couldn't delete a file
- else
- wscript.stdout.write ","
- doCRLF = 1
- end if
- next
- Set objFolder = Nothing
- if doCRLF > 0 then
- wscript.stdout.write vbCRLF
- end if
- end sub
- sub DeleteSubfolderFiles(strFolder)
- ' Deletes all files only, within subfolders of the current folder
- dim objFolder, objFile, objSubFolder, doCRLF
- on error resume next
- doCRLF = 0
- set objFolder=objFSO.GetFolder(strFolder)
- if Err.Number<>0 then
- Err.Clear
- set objFolder = Nothing
- Exit Sub ' Couldn't get a handle to the folder, so can't do anything
- end if
- for each objSubFolder in objFolder.SubFolders
- for each objFile in objSubFolder.Files
- objFile.Delete true
- if Err.Number<>0 then
- wscript.stdout.write "x"
- doCRLF = 1
- Err.Clear ' In case we couldn't delete a file
- else
- wscript.stdout.write ","
- doCRLF = 1
- end if
- next
- next
- Set objFolder = Nothing
- if doCRLF > 0 then
- wscript.stdout.write vbCRLF
- end if
- end sub
- 'Chrome Subroutine
- Sub DeleteFileFromFolder(Path)
- For Each File In objFSO.GetFolder(Path).Files
- DeleteAllow File
- Next
- For Each File In objFSO.GetFolder(Path).SubFolders
- DeleteFileFromFolder File.Path
- Next
- End Sub
- Sub DeleteAllow(File)
- 'Bookmarks remain same
- If NOT(StrComp(Left(File.Name, 9), "Bookmarks", vbTextCompare)) = 0 Then
- Wscript.Echo File.Path + " Deleted"
- On Error Resume Next
- objFSO.DeleteFile File.Path, True
- End If
- End Sub
- Sub ProcessTerminate(Process)
- Const StrComputer = "."
- Dim WshShell, ObjWMIService, ProcessList, ObjProcess
- Set WshShell = CreateObject("WScript.Shell")
- Set ObjWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & StrComputer & "\root\cimv2")
- Set ProcessList = ObjWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = '" & Process & "'")
- For Each ObjProcess in ProcessList
- On Error Resume Next
- ObjProcess.Terminate
- Wscript.Echo "Process Terminated, ProcessId=" & ObjProcess.ProcessId & " (" & ObjProcess.Name & ")"
- Next
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement