groone
asked on
Clearing History and Temp Inet directories
The kill statement doesnt clear the temporary internet directory nor does it clear the history directory. How would I accomplish clearing these folders?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
'--Bas module code----
*************
' Removing IE Temporary Files
'*************************
' E-Mail: edanmo@geocities.com
' Web Page: http://www.domaindlx.com/e_morcillo
'
Option Explicit
Type UUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Public Const CLSCTX_INPROC_SERVER = 1
Declare Function CoCreateInstance Lib "ole32" (rclsid As UUID, ByVal pUnkOuter As Long, ByVal dwClsContext As Long, riid As UUID, ppv As Object) As Long
Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)
Declare Function CLSIDFromString Lib "ole32.dll" (ByVal lpOLEStr As Long, pclsid As UUID) As Long
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const KEY_ALL_ACCESS = &HF003F
Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Declare Function RegCloseKey Lib "advapi32" (ByVal hKey As Long) As Long
Public Const CSIDL_INTERNET_CACHE = &H20&
Declare Function SHGetSpecialFolderLocation
Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidl As Long, ByVal pszPath As String) As Long
'Form code
'Place command button cmdClean and Label1 at your form
Option Explicit
' Implement IEmptyVolumeCacheCallBack to
' receive messages from the cleaner
Implements IEmptyVolumeCacheCallBack
' CLSIDs and IIDs used by this program
Const CLSID_TemporaryCleaner = "{9B0EFD60-F7B0-11D0-BAEF-
Const CLSID_OffLineCleaner = "{8E6E6079-0CB7-11D2-8F10-
Const IID_IEmptyVolumeCache = "{8FCE5227-04DA-11d1-A004-
' Registry keys used by the cleaners
Const HKEY_OFFLINE = "Software\Microsoft\Window
Const HKEY_TEMPORARY = "Software\Microsoft\Window
Dim TemporaryFiles As IEmptyVolumeCache
Dim OffLinePages As IEmptyVolumeCache
Dim Size As Currency
'*************************
' CreateCleaner
'
' Creates a cleaner object from its CLSID
'*************************
Private Function CreateCleaner(ByVal GUID As String) As IEmptyVolumeCache
Dim CLSID As UUID, IID As UUID
' Convert the strings to
' GUID structs
CLSIDFromString StrPtr(GUID), CLSID
CLSIDFromString StrPtr(IID_IEmptyVolumeCac
' Instantiate the handler
CoCreateInstance CLSID, 0&, CLSCTX_INPROC_SERVER, IID, CreateCleaner
End Function
'*************************
' Removes the files
'*************************
Private Sub cmdClean_Click()
OffLinePages.Purge Size / 10000, Me
TemporaryFiles.Purge Size / 10000, Me
Unload Me
End Sub
'*************************
' InitializeCleaners
'
' Initializes the cleaner objects
'*************************
Private Sub InitializeCleaners()
Dim hKey As Long, Drive As String, PIDL As Long
Dim Name As Long, Desc As Long, Flags As Long
' Get the Temporary Files path
Drive = Space$(260)
SHGetSpecialFolderLocation
SHGetPathFromIDList PIDL, Drive
Drive = Left$(Drive, 3)
CoTaskMemFree PIDL
' Open the OffLine pages registry key
If RegOpenKeyEx(HKEY_LOCAL_MA
' Initialize the OffLine pages cleaner
OffLinePages.Initialize hKey, Drive, Name, Desc, Flags
' Free unused memory
CoTaskMemFree Name
CoTaskMemFree Desc
' Close the key
RegCloseKey hKey
End If
' Open the TemporaryFiles registry key
If RegOpenKeyEx(HKEY_LOCAL_MA
' Initialize the OffLine pages cleaner
TemporaryFiles.Initialize hKey, Drive, Name, Desc, Flags
' Free unused memory
CoTaskMemFree Name
CoTaskMemFree Desc
' Close the key
RegCloseKey hKey
End If
End Sub
Private Sub Form_Load()
Dim Size1 As Currency
' Create the cleaner objects
Set OffLinePages = CreateCleaner(CLSID_OffLin
Set TemporaryFiles = CreateCleaner(CLSID_Tempor
' Initialize the cleaners
InitializeCleaners
' Get the space used by the files
TemporaryFiles.GetSpaceUse
Size = Size1 * 10000
OffLinePages.GetSpaceUsed Size1, Me
Size = Size + (Size1 * 10000)
' Show the space in the form
lblInfo.Caption = "The Temporary Internet Files are using " & Format(Size / 1024 / 1024, "00.00") & " Mb on the drive. Press Clean button to remove them."
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim Flags As Long
' Destroy the objects
OffLinePages.Deactivate Flags
TemporaryFiles.Deactivate Flags
Set OffLinePages = Nothing
Set TemporaryFiles = Nothing
End Sub
Private Sub IEmptyVolumeCacheCallBack_
'
End Sub
Private Sub IEmptyVolumeCacheCallBack_
'
End Sub
Cheers