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