Page 1 of 1 1
Topic Options
#128714 - 2004-10-31 06:31 AM Clear Internet Explorer Cache
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11574
Loc: CA
Here is an example script that terminates Internet Explorer and then searches the Registry for all profiles and clears the CACHE of each of the profiles. It DOES NOT remove the INDEX.DAT file as it is in use, but it does clear up a lot of room on the hard drive by deleting all the cache files and folders not in use by some process.

This example script requires WMI and was written/tested on KiXtart v4.22 using the 2 UDF files listed below in the code.


Code:

Break On
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')

; Declares the variables
Dim $UserKeys,$Key,$Value,$Cache,$proc
; $UserKeys holds the array of returned data from the ArrayEnumKey UDF
$UserKeys=ArrayEnumKey('HKU')
; Sets Internet Explorer as the process to terminate
$proc = "IEXPLORE.EXE" ; Internet Explorer
; Terminates the process set by $proc
EndProc($proc)

; Runs the code against every element found in the array
For Each $Key In $UserKeys
; Excludes keys/values with specified names from being returned
If Not InStr($Key,'.DEFAULT') And Not InStr($Key,'Classes')
; Returns the path to the location of IE Cache folders
$Cache=ReadValue('HKU'+$Key+'\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders','Cache')
; Checks if the path specified exists or not
If Exist($Cache+'\Content.IE5')
; If the path does exist it shells out to the command processor and runs a Remove Directory call
; By removing the semi-colon from the end of the code line you can prevent output from being displayed
? SHELL '%COMSPEC% /C RD /s /q ' + '"' + $Cache+'\Content.IE5'+'"' ;+' >nul 2>nul'
EndIf
EndIf
Next



;ARRAYENUMKEY() - Creates an array of names of the subkeys contained in a registry key
;http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=81940

Function ArrayEnumKey($regsubkey)
Dim $retcode, $subkeycounter, $currentsubkey, $subkeyarray
If Not KeyExist($regsubkey)
Exit 87
EndIf
$subkeycounter=0
Do
$currentsubkey=EnumKey($regsubkey,$subkeycounter)
If Not @ERROR
ReDim Preserve $subkeyarray[$subkeycounter]
$subkeyarray[$subkeycounter]=$currentsubkey
$subkeycounter=$subkeycounter+1
EndIf
Until @ERROR
$arrayenumkey=$subkeyarray
Exit 0
EndFunction


;EndProc() - Terminate a process using WMI
;http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=82164

Function EndProc($proc, optional $strComputer)
DIM $Process
If $strComputer=''
$strComputer='.'
EndIf
For Each $Process In GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $strComputer + "\root\cimv2").ExecQuery("Select * from Win32_Process where Name= " +'"'+$Proc+'"')
$Process=$Process.Terminate
Next
EndFunction


Top
#172321 - 2007-01-03 03:22 AM Re: Clear Internet Explorer Cache [Re: NTDOC]
Shaba1 Offline
Fresh Scripter

Registered: 2005-08-20
Posts: 44
Ok is there a way of getting this script without copying and pasting so I can retain the line breaks.
Top
#172323 - 2007-01-03 05:32 AM Re: Clear Internet Explorer Cache [Re: Shaba1]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11574
Loc: CA
Copy it then paste it to WORDPAD or MS WORD, then copy again from WORDPAD and paste to NOTEPAD or your Editor and the formatting should remain.

ps. This is just an example script and is NOT a secure method of removing cache files if that's what you're looking for. It's just an example.

Crap Cleaner is a better free solution if that's what you're really looking for. This gives you an idea though on how to script it, and it to can be improved with better coding.
http://www.ccleaner.com/



Edited by NTDOC (2007-01-03 05:35 AM)

Top
#172324 - 2007-01-03 05:34 AM Re: Clear Internet Explorer Cache [Re: Shaba1]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Run it through Word or Wordpad to retain the formatting.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#185424 - 2008-02-18 11:24 AM Re: Clear Internet Explorer Cache [Re: Les]
Chelseauk Offline
Fresh Scripter

Registered: 2007-08-28
Posts: 6
Hi,

Script does work - fine with IE 6. It leaves behind the contents of the root of temporary Internet Files - anyone know if these are important from a clear cache kind of way (if you do it via IE it kills them).


Edited by Chelseauk (2008-02-18 12:36 PM)

Top
#185453 - 2008-02-19 12:31 AM Re: Clear Internet Explorer Cache [Re: Chelseauk]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11574
Loc: CA
Hello,

This is an OLD script and was only an idea and not really meant as production script. I would recommend using a product like CCleaner if you really need to do this, or where possible install IE7 which has much better removal / cleanup capabilities.

Now if you're using KiX 4.53 the script can be written to remove INUSE files on reboot if wanted.

Top
Page 1 of 1 1


Moderator:  NTDOC, ShaneEP, Mart, Radimus, Glenn Barnas, Jochen, Allen 
Hop to:
Shout Box

Who's Online
0 registered and 46 anonymous users online.
Newest Members
ROBECCO80, TsuyoiSaigai, a5tr0, FoolZero, DaveE
17657 Registered Users

Generated in 0.035 seconds in which 0.011 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org