Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > Access数据库-模块/函数/VBA

access API集中营--清除IE缓存

时 间:2009-09-16 00:18:30
作 者:朱亦文   ID:61  城市:岳阳
摘 要:Access API集中营 » 清除IE缓存
正 文:

'Access API集中营 » 清除IE缓存

 

Option Compare Database
Option Explicit
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" _
                                                Alias "FindFirstUrlCacheEntryA" _
                                                (ByVal lpszUrlSearchPattern As String, _
                                                 lpFirstCacheEntryInfo As Any, _
                                                 lpdwFirstCacheEntryInfoBufferSize As Long) As Long
Private Declare Function FindNextUrlCacheEntry Lib "wininet" _
                                               Alias "FindNextUrlCacheEntryA" _
                                               (ByVal hEnumHandle As Long, _
                                                lpNextCacheEntryInfo As Any, _
                                                lpdwNextCacheEntryInfoBufferSize As Long) As Long
Private Declare Function FindCloseUrlCache Lib "wininet" _
                                           (ByVal hEnumHandle As Long) As Long
Private Declare Function DeleteUrlCacheEntry Lib "wininet" _
                                             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
Public Sub ClearIECache()
    Dim icei As INTERNET_CACHE_ENTRY_INFO
    Dim hFile As Long
    Dim cachefile As String
    Dim posUrl As Long
    Dim posEnd As Long
    Dim dwBuffer As Long
    Dim pntrICE As Long
   
    hFile = FindFirstUrlCacheEntry(0&, ByVal 0, dwBuffer)
   
    If (hFile = ERROR_CACHE_FIND_FAIL) And _
       (Err.LastDllError = ERROR_INSUFFICIENT_BUFFER) Then
       
        pntrICE = LocalAlloc(LMEM_FIXED, dwBuffer)
       
        If pntrICE <> 0 Then
            CopyMemory ByVal pntrICE, dwBuffer, 4
            hFile = FindFirstUrlCacheEntry(vbNullString, _
                                           ByVal pntrICE, _
                                           dwBuffer)
           
            If hFile <> ERROR_CACHE_FIND_FAIL Then
                Do
                    CopyMemory icei, ByVal pntrICE, Len(icei)
                    If (icei.CacheEntryType And _
                        NORMAL_CACHE_ENTRY) = NORMAL_CACHE_ENTRY Then
                       
                        cachefile = GetStrFromPtrA(icei.lpszSourceUrlName)
                        If Left(cachefile, 8) <> "Visited:" Then
                            Debug.Print cachefile
                            DeleteUrlCacheEntry cachefile
                        End If
                    End If
                  
                    dwBuffer = 0
                    Call FindNextUrlCacheEntry(hFile, ByVal 0, dwBuffer)
                   
                    pntrICE = LocalAlloc(LMEM_FIXED, dwBuffer)
                    CopyMemory ByVal pntrICE, dwBuffer, 4
                Loop While FindNextUrlCacheEntry(hFile, ByVal pntrICE, dwBuffer)
            End If    'hFile
        End If    'pntrICE
    End If    'hFile
   
    Call LocalFree(pntrICE)
    Call FindCloseUrlCache(hFile)
End Sub
Private Function GetStrFromPtrA(ByVal lpszA As Long) As String
    GetStrFromPtrA = String$(lstrlenA(ByVal lpszA), 0)
    Call lstrcpyA(ByVal GetStrFromPtrA, ByVal lpszA)
End Function

 

调用方法:
Call ClearIECache



Access软件网QQ交流群 (群号:54525238)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助