Hi
Is there a way to clear out the cache and history using VBA code? (not using sendkeys). i know how to clear the cookies folder, but cache and history are an unknown. any help would be appreciated.
thanks
tx
Printable View
Hi
Is there a way to clear out the cache and history using VBA code? (not using sendkeys). i know how to clear the cookies folder, but cache and history are an unknown. any help would be appreciated.
thanks
tx
Yes, but from which office app and what exactly are you trying to do?
moved
from Excel, it is a macro in Excel. i want to be able to clear out the IE browser cache and history using a macro.Quote:
Originally Posted by RobDog888
thanks for the reply
Hi
here is something directly from the microsoft's website...
1) CLEARING CACHE
Use WinInet API FindFirstURLCacheEntry to find the first cache entry and use FindNextUrlCacheEntry to enumerate through the cache. Use DeleteUrlCacheEntry to delete each entry.
Note that FindFirstUrlCacheGroup, FindNextUrlCacheGroup, and DeleteUrlCacheGroup are used in the following example. These API functions have only became available with Internet Explorer 5, so proper checking as shown is needed to prevent errors.
The following steps show you how to use the WinInet API in Visual Basic to clear all the files in the cache.
1. Create a new Visual Basic standard EXE project.
2. Create a command button under form1.
3. Paste the following code in the module of form1:
VB Code:
Option Explicit Private Declare Function FindFirstUrlCacheGroup Lib "wininet.dll" ( _ ByVal dwFlags As Long, _ ByVal dwFilter As Long, _ ByRef lpSearchCondition As Long, _ ByVal dwSearchCondition As Long, _ ByRef lpGroupId As Date, _ ByRef lpReserved As Long) As Long Private Declare Function FindNextUrlCacheGroup Lib "wininet.dll" ( _ ByVal hFind As Long, _ ByRef lpGroupId As Date, _ ByRef lpReserved As Long) As Long Private Declare Function DeleteUrlCacheGroup Lib "wininet.dll" ( _ ByVal sGroupID As Date, _ ByVal dwFlags As Long, _ ByRef lpReserved As Long) As Long Private Declare Function FindFirstUrlCacheEntry Lib "wininet.dll" Alias "FindFirstUrlCacheEntryA" ( _ ByVal lpszUrlSearchPattern As String, _ ByRef lpFirstCacheEntryInfo As INTERNET_CACHE_ENTRY_INFO, _ ByRef lpdwFirstCacheEntryInfoBufferSize As Long) As Long Private Type INTERNET_CACHE_ENTRY_INFO dwStructSize As Long szRestOfData(1024) As Long End Type Private Declare Function DeleteUrlCacheEntry Lib "wininet.dll" Alias "DeleteUrlCacheEntryA" ( _ ByVal lpszUrlName As Long) As Long Private Declare Function FindNextUrlCacheEntry Lib "wininet.dll" Alias "FindNextUrlCacheEntryA" ( _ ByVal hEnumHandle As Long, _ ByRef lpNextCacheEntryInfo As INTERNET_CACHE_ENTRY_INFO, _ ByRef lpdwNextCacheEntryInfoBufferSize As Long) As Long Private Const CACHGROUP_SEARCH_ALL = &H0 Private Const ERROR_NO_MORE_FILES = 18 Private Const ERROR_NO_MORE_ITEMS = 259 Private Const CACHEGROUP_FLAG_FLUSHURL_ONDELETE = &H2 Private Const BUFFERSIZE = 2048 Private Sub Command1_Click() Dim sGroupID As Date Dim hGroup As Long Dim hFile As Long Dim sEntryInfo As INTERNET_CACHE_ENTRY_INFO Dim iSize As Long On Error Resume Next ' Delete the groups hGroup = FindFirstUrlCacheGroup(0, 0, 0, 0, sGroupID, 0) ' To avoid error using it with IE4 as FindFirstUrlCacheGroup is not implemented If Err.Number <> 453 Then If (hGroup = 0) And (Err.LastDllError <> 2) Then MsgBox "An error occurred enumerating the cache groups" & Err.LastDllError Exit Sub End If Else Err.Clear End If If (hGroup <> 0) Then 'we succeeded in finding the first cache group.. enumerate and 'delete Do If (0 = DeleteUrlCacheGroup(sGroupID, CACHEGROUP_FLAG_FLUSHURL_ONDELETE, 0)) Then ' To avoid error using it with IE4 as FindFirstUrlCacheGroup is not implemented If Err.Number <> 453 Then MsgBox "Error deleting cache group " & Err.LastDllError Exit Sub Else Err.Clear End If End If iSize = BUFFERSIZE If (0 = FindNextUrlCacheGroup(hGroup, sGroupID, iSize)) And (Err.LastDllError <> 2) Then MsgBox "Error finding next url cache group! - " & Err.LastDllError End If Loop Until Err.LastDllError = 2 End If ' Delete the files sEntryInfo.dwStructSize = 80 iSize = BUFFERSIZE hFile = FindFirstUrlCacheEntry(0, sEntryInfo, iSize) If (hFile = 0) Then If (Err.LastDllError = ERROR_NO_MORE_ITEMS) Then GoTo done End If MsgBox "ERROR: FindFirstUrlCacheEntry - " & Err.LastDllError Exit Sub End If Do If (0 = DeleteUrlCacheEntry(sEntryInfo.szRestOfData(0))) _ And (Err.LastDllError <> 2) Then Err.Clear End If iSize = BUFFERSIZE If (0 = FindNextUrlCacheEntry(hFile, sEntryInfo, iSize)) And (Err.LastDllError <> ERROR_NO_MORE_ITEMS) Then MsgBox "Error: Unable to find the next cache entry - " & Err.LastDllError Exit Sub End If Loop Until Err.LastDllError = ERROR_NO_MORE_ITEMS done: MsgBox "cache cleared" Command1.Enabled = True End Sub
Hope this helps....
Let me see if i can find something for the 'History' :)
thanks
i found something very similar, but the history option is still somewhat elusive.
also, was wondernig if there is a way to tweak the code so it is not form dependent.
tx
I think I found something...
I am not sure. i haven't tested it yet...
VB Code:
' Clear the IE History Public Sub ClearIEHistory() Const HKEY_CURRENT_USER = &H80000001 Dim sKey As String sKey = "Software\Microsoft\Internet Explorer\TypedURLs" ' delete the key that contains the URLs the history DeleteRegistryKey HKEY_CURRENT_USER, sKey ' recreate the key, empty CreateRegistryKey HKEY_CURRENT_USER, sKey End Sub
you will require the DeleteRegistryKey and CreateRegistryKey routines which are mentioned below:
DELETE REGISTRY KEY
VB Code:
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" _ (ByVal hKey As Long, ByVal lpSubKey As String) As Long ' Delete a registry key ' ' Under Windows NT it doesn't work if the key contains subkeys Sub DeleteRegistryKey(ByVal hKey As Long, ByVal KeyName As String) RegDeleteKey hKey, KeyName End Sub
CREATE REGISTRY KEY
VB Code:
Private Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias _ "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _ ByVal Reserved As Long, ByVal lpClass As Long, ByVal dwOptions As Long, _ ByVal samDesired As Long, ByVal lpSecurityAttributes As Long, _ phkResult As Long, lpdwDisposition As Long) As Long Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As _ Long Const KEY_READ = &H20019 ' ((READ_CONTROL Or KEY_QUERY_VALUE Or ' KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not ' SYNCHRONIZE)) Const REG_OPENED_EXISTING_KEY = &H2 ' Create a registry key, then close it ' Returns True if the key already existed, False if it was created Function CreateRegistryKey(ByVal hKey As Long, ByVal KeyName As String) As _ Boolean Dim handle As Long, disposition As Long If RegCreateKeyEx(hKey, KeyName, 0, 0, 0, 0, 0, handle, disposition) Then Err.Raise 1001, , "Unable to create the registry key" Else ' Return True if the key already existed. CreateRegistryKey = (disposition = REG_OPENED_EXISTING_KEY) ' Close the key. RegCloseKey handle End If End Function
I don't know if this is what you want... Hope it helps :)
thanks for the code. it clears the address bar it seems, but not the history.
thanks for the input
I am trying to do something similar in excel but am not sure how I can create a new EXE project? Can I run the same code from a module?
Also will this work for IE7?
Any inputs will be very helpful as I just started coding in VB-Excel. thank you
Hi,
I am newbie to VBA.
Thank you very much for ur code.
It saved my life at the dead end.
Its working fine in my environment Window XP and MsWord 2003
Thanks a lot.
With Regards,
Ashok,
Quote:
Originally Posted by koolsid
Hi All,
It was working in XP and Ms word 2002 Environment.
When I migrated my application to Windows 2003 and Ms word 2003. There is a exception given as err.LastDllError=87.
Please help me asap.
I managing with the last result in XP environment. I need to migrate to windows 2003.
Solution applaudable.
With regards,
AshokKumar.
Keep it simple
Sub Clear_Temp_Files()
Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8 "
End Sub
Sub Clear_Cookies()
Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2"
End Sub
Sub Clear_History()
Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1"
End Sub
Sub Clear_Form_Data()
Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16"
End Sub
Sub Clear_Saved_Passwords()
Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32"
End Sub
Sub Clear_All()
Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255"
End Sub
Sub Clear_Clear_Add_ons_Settings()
Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351"
End Sub
Awww!
Its simple to use!
Thanks Technorobbo!
I am in AWEEEEEE
Very good.
I wonder if there is also a simple shell command to change proxy settings in internet explorer.
hi, i want to set internet zone setting to custom level...(high or low) with vb6
is there any way to do this.?
or any other way?
help please.
i just want to disable or enable java scripting in web browser with vb6.
i'll do it manually and it's working perfect. but i want to do this with my project automatically with coding.
anyone here to solve this problem.
thankx in advance.
hi, i want to set internet zone setting to custom level...(high or low) with vb6
is there any way to do this.? and adding or removing site to trusted zone or restricted zone.
Example:
to clear ie history.
or any other way?Code:Sub Clear_History()
Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1"
End Sub
help please.
i just want to disable or enable java scripting in web browser with vb6.
i'll do it manually and it's working perfect. but i want to do this with my project automatically with coding.
anyone here to solve this problem.
Hi,
I'm sorry that I answer (to) the old question, but I want not open a new topic.
My code is the following:
For an example:
Private Sub xxxx
End SubCode:Shell("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1")
Shell("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2")
Shell("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8 ")
Shell("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16")
Shell("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32")
Shell("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255")
Shell("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351")
Best regards
TheSuperego