Saturday, June 23, 2012

The real way to delete internet explorer and google chrome cached data with a script, even if they are running and you getting access denied message.

Here we are:





Set objShell = CreateObject("WScript.Shell")


'KILL MICROSOFT INTERNET EXPLORER
objShell.run("taskkill /F /IM iexplore.exe")
WScript.Sleep 500


'WAIT FOR A WHILE AND KILL WINDOWS EXPLORER
objShell.run("taskkill /F /IM explorer.exe")
WScript.Sleep 500




'DELETE CURRENT USER INTERNET EXPLORER TEMPORARY DATA


Set objShell = CreateObject("WScript.Shell")
userProfilePath = objShell.ExpandEnvironmentStrings("%UserProfile%")


Set fso=CreateObject("Scripting.FileSystemObject")
CleanPath=userProfilePath & "\Local Settings\Temporary Internet Files\"
For Each file In fso.GetFolder(CleanPath).Files
file.attributes = file.attributes And Not 1
file.delete
Next


Set fso = CreateObject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder(CleanPath)
arrFolders = Array()
For Each oFolder In oFolder.SubFolders
' Note : Only use *lowercase* letters in the folder names below:
If Not LCase(oFolder.Name) = "foldera" _
And Not LCase(oFolder.Name) = "folderb" _
And Not LCase(oFolder.Name) = "folderc" Then
intCount = UBound(arrFolders) + 1
ReDim Preserve arrFolders(intCount)
arrFolders(intCount) = oFolder.Path
End If
Next
For n = 0 To UBound(arrFolders)
fso.DeleteFolder arrFolders(n), True
Next


'DELETE DEFAULT USER INTERNET EXPLORER TEMPORARY DATA


Set fso=CreateObject("Scripting.FileSystemObject")
CleanPath="C:\Documents and Settings\Default User\Local Settings\Temporary Internet Files"
For Each file In fso.GetFolder(CleanPath).Files
file.attributes = file.attributes And Not 1
file.delete
Next


Set fso = CreateObject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder(CleanPath)
arrFolders = Array()
For Each oFolder In oFolder.SubFolders
' Note : Only use *lowercase* letters in the folder names below:
If Not LCase(oFolder.Name) = "foldera" _
And Not LCase(oFolder.Name) = "folderb" _
And Not LCase(oFolder.Name) = "folderc" Then
intCount = UBound(arrFolders) + 1
ReDim Preserve arrFolders(intCount)
arrFolders(intCount) = oFolder.Path
End If
Next
For n = 0 To UBound(arrFolders)
fso.DeleteFolder arrFolders(n), True
Next


'DELETE CURRENT USER GOOGLE CHROME TEMPORARY DATA


objShell.run("taskkill /F /IM chrome.exe")
WScript.Sleep 500
CleanPath=userProfilePath & "\Local Settings\Application Data\Google\Chrome\User Data\Default\Cache"
For Each file In fso.GetFolder(CleanPath).Files
file.attributes = file.attributes And Not 1
file.delete
Next


Set fso = CreateObject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder(CleanPath)
arrFolders = Array()
For Each oFolder In oFolder.SubFolders
' Note : Only use *lowercase* letters in the folder names below:
If Not LCase(oFolder.Name) = "foldera" _
And Not LCase(oFolder.Name) = "folderb" _
And Not LCase(oFolder.Name) = "folderc" Then
intCount = UBound(arrFolders) + 1
ReDim Preserve arrFolders(intCount)
arrFolders(intCount) = oFolder.Path
End If
Next
For n = 0 To UBound(arrFolders)
fso.DeleteFolder arrFolders(n), True
Next


'WAIT FOR A WHILE AND START WINDOWS EXPLORER AGAIN ;D
WScript.Sleep 500
objShell.run("explorer.exe")


'DELETE ALL FROM IE
objShell.run("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255")


'DELETE IE FILES AND SETTINGS STORED BY ADDONS 
objShell.run("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351")


Wscript.Quit


This can also be used to delete locked IE and Chrome files that are in use by those browsers. Many times there is filenames without extension. So if you try to delete these files with a simple "del  *.* /Q /S /F" command it doesn't work!

No comments: