|
|
|
Click here to copy the following block | Option Explicit
Const MAX_ENTRIES = 5000
Private Const ERROR_CACHE_FIND_FAIL As Long = 0 Private Const ERROR_CACHE_FIND_SUCCESS As Long = 1 Private Const ERROR_FILE_NOT_FOUND As Long = 2 Private Const ERROR_ACCESS_DENIED As Long = 5 Private Const ERROR_INSUFFICIENT_BUFFER As Long = 122 Private Const MAX_PATH As Long = 260 Private Const MAX_CACHE_ENTRY_INFO_SIZE As Long = 4096
Private Const LMEM_FIXED As Long = &H0 Private Const LMEM_ZEROINIT As Long = &H40 Private Const LPTR As Long = (LMEM_FIXED Or LMEM_ZEROINIT)
Private Const NORMAL_CACHE_ENTRY As Long = &H1 Private Const EDITED_CACHE_ENTRY As Long = &H8 Private Const TRACK_OFFLINE_CACHE_ENTRY As Long = &H10 Private Const TRACK_ONLINE_CACHE_ENTRY As Long = &H20 Private Const STICKY_CACHE_ENTRY As Long = &H40 Private Const SPARSE_CACHE_ENTRY As Long = &H10000 Private Const COOKIE_CACHE_ENTRY As Long = &H100000 Private Const URLHISTORY_CACHE_ENTRY As Long = &H200000 Private Const URLCACHE_FIND_DEFAULT_FILTER As Long = NORMAL_CACHE_ENTRY Or _ COOKIE_CACHE_ENTRY Or _ URLHISTORY_CACHE_ENTRY Or _ TRACK_OFFLINE_CACHE_ENTRY Or _ TRACK_ONLINE_CACHE_ENTRY Or _ STICKY_CACHE_ENTRY Private Type FILETIME dwLowDateTime As Long dwHighDateTime As Long End Type
Private Type INTERNET_CACHE_ENTRY_INFO dwStructSize As Long lpszSourceUrlName As Long lpszLocalFileName As Long CacheEntryType As Long dwUseCount As Long dwHitRate As Long dwSizeLow As Long dwSizeHigh As Long LastModifiedTime As FILETIME ExpireTime As FILETIME LastAccessTime As FILETIME LastSyncTime As FILETIME lpHeaderInfo As Long dwHeaderInfoSize As Long lpszFileExtension As Long dwExemptDelta As Long End Type
Private Declare Function FindFirstUrlCacheEntry Lib "Wininet.dll" _ Alias "FindFirstUrlCacheEntryA" _ (ByVal lpszUrlSearchPattern As String, _ lpFirstCacheEntryInfo As Any, _ lpdwFirstCacheEntryInfoBufferSize As Long) As Long
Private Declare Function FindNextUrlCacheEntry Lib "Wininet.dll" _ Alias "FindNextUrlCacheEntryA" _ (ByVal hEnumHandle As Long, _ lpNextCacheEntryInfo As Any, _ lpdwNextCacheEntryInfoBufferSize As Long) As Long
Private Declare Function FindCloseUrlCache Lib "Wininet.dll" _ (ByVal hEnumHandle As Long) As Long
Private Declare Function DeleteUrlCacheEntry Lib "Wininet.dll" _ Alias "DeleteUrlCacheEntryA" _ (ByVal lpszUrlName As String) As Long
Private Declare Sub CopyMemory Lib "kernel32" _ Alias "RtlMoveMemory" _ (pDest As Any, _ pSource As Any, _ ByVal dwLength As Long)
Private Declare Function lstrcpyA Lib "kernel32" _ (ByVal RetVal As String, ByVal Ptr As Long) As Long
Private Declare Function lstrlenA Lib "kernel32" _ (ByVal Ptr As Any) As Long
Private Declare Function LocalAlloc Lib "kernel32" _ (ByVal uFlags As Long, _ ByVal uBytes As Long) As Long
Private Declare Function LocalFree Lib "kernel32" _ (ByVal hMem As Long) As Long
Private Sub Command2_Click() Dim cachefile As String Dim i As Long, ret As Long For i = 0 To List1.ListCount - 1 cachefile = List1.List(i) ret = DeleteUrlCacheEntry(cachefile) Next Command1_Click End Sub
Private Sub Form_Load() Command1.Caption = "Load Entries" Command2.Caption = "Delete All Entries" With Combo1 .AddItem "Normal Entry": .ItemData(.NewIndex) = NORMAL_CACHE_ENTRY .AddItem "Edited Entry (IE5)": .ItemData(.NewIndex) = EDITED_CACHE_ENTRY .AddItem "Offline Entry": .ItemData(.NewIndex) = TRACK_OFFLINE_CACHE_ENTRY .AddItem "Online Entry": .ItemData(.NewIndex) = TRACK_ONLINE_CACHE_ENTRY .AddItem "Stick Entry": .ItemData(.NewIndex) = STICKY_CACHE_ENTRY .AddItem "Sparse Entry": .ItemData(.NewIndex) = SPARSE_CACHE_ENTRY .AddItem "Cookies": .ItemData(.NewIndex) = COOKIE_CACHE_ENTRY .AddItem "Visited History": .ItemData(.NewIndex) = URLHISTORY_CACHE_ENTRY .AddItem "Default Filter": .ItemData(.NewIndex) = URLCACHE_FIND_DEFAULT_FILTER .ListIndex = 0 End With End Sub
Private Sub Command1_Click() Dim TotalEntries As Long Me.Caption = "Loading Entries ..." List1.Clear
TotalEntries = LoadCach(Combo1.ItemData(Combo1.ListIndex)) Me.Caption = Format$(List1.ListCount, "###,###,###,##0") & " Entries found for " & Combo1.Text MsgBox Me.Caption End Sub
Private Sub List1_Click() Text1.Text = List1.List(List1.ListIndex) End Sub
Private Function LoadCach(CacheType As Long) As Long
Dim CacheEntry As INTERNET_CACHE_ENTRY_INFO Dim hFile As Long Dim cachefile As String Dim nCount As Long Dim dwBuffer As Long Dim ptrCacheEntry As Long Dim ret As Long
dwBuffer = 0
hFile = FindFirstUrlCacheEntry(vbNullString, ByVal 0, dwBuffer)
If (hFile = ERROR_CACHE_FIND_FAIL) And _ (Err.LastDllError = ERROR_INSUFFICIENT_BUFFER) Then
ptrCacheEntry = LocalAlloc(LMEM_FIXED, dwBuffer)
If ptrCacheEntry <> 0 Then
CopyMemory ByVal ptrCacheEntry, dwBuffer, 4
hFile = FindFirstUrlCacheEntry(vbNullString, ByVal ptrCacheEntry, dwBuffer)
If hFile <> ERROR_CACHE_FIND_FAIL Then
Do CopyMemory CacheEntry, ByVal ptrCacheEntry, Len(CacheEntry)
If (CacheEntry.CacheEntryType And CacheType) Then cachefile = GetStrFromPtrA(CacheEntry.lpszSourceUrlName) List1.AddItem cachefile nCount = nCount + 1 End If Call LocalFree(ptrCacheEntry) If nCount > MAX_ENTRIES Then ret = MsgBox("Maximum limit is set to " & MAX_ENTRIES & ". Do you want to continue?", vbYesNo + vbDefaultButton2) If ret = vbNo Then Exit Do End If dwBuffer = 0 Call FindNextUrlCacheEntry(hFile, ByVal 0, dwBuffer)
ptrCacheEntry = LocalAlloc(LMEM_FIXED, dwBuffer) CopyMemory ByVal ptrCacheEntry, dwBuffer, 4
Loop While FindNextUrlCacheEntry(hFile, ByVal ptrCacheEntry, dwBuffer)
End If End If End If
Call LocalFree(ptrCacheEntry) Call FindCloseUrlCache(hFile)
LoadCach = nCount End Function
Private Function GetStrFromPtrA(ByVal lpszA As Long) As String GetStrFromPtrA = String$(lstrlenA(ByVal lpszA), 0) Call lstrcpyA(ByVal GetStrFromPtrA, ByVal lpszA) End Function |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|