VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)

VB爱好者乐园(VBGood)

 找回密码
 立即注册
搜索
查看: 13756|回复: 24

[经验技巧] VB如何删除Temporary Internet Files?【已解决】

[复制链接]
 楼主| 发表于 2008-11-18 11:25:40 | 显示全部楼层 |阅读模式
如何删除C:\Documents and Settings\Administrator\Local Settings\Temporary Internet Files下所有缓存内容?

搜了论坛上,没点头绪
看了msdn这个
http://support.microsoft.com/default.aspx?scid=kb;en-us;311289

说:
WinInet Functions
To clear the cache directly, you can use the following WinInet functions:
• Use the FindFirstURLCacheEntry function to find the first cache entry.
• Use the FindNextUrlCacheEntry function to enumerate through the cache.
• Use the DeleteUrlCacheEntry function to delete each entry.
________________________________________________


How to use the functions?or,How to clear the cache when your application hosts a WebBrowser control?

Can you tell me?thanks

[ 本帖最后由 261001126 于 2008-11-20 13:56 编辑 ]
发表于 2008-11-18 11:27:57 | 显示全部楼层
试试:

DeleteUrlCacheEntry URL
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-11-18 12:27:09 | 显示全部楼层
IE的缓存和Cookies,可以通过WinInet.dll库中的函数来进行操作的如果要查找所有的缓存和Cookies,需要使用FindFirstUrlCacheEntry和FindNextUrlCacheEntry这两个函数如果要删除相对应的缓存和Cookies,就使用DeleteUrlCacheEntry函数源代码如下: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 DeleteCacheURLList()
   
    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)
                   Call DeleteUrlCacheEntry(cachefile)

                End If
              
                Call LocalFree(pntrICE)
              
                dwBuffer = 0
                Call FindNextUrlCacheEntry(hFile, ByVal 0, dwBuffer)
              
               'allocate and assign the memory to the pointer
                pntrICE = LocalAlloc(LMEM_FIXED, dwBuffer)
                CopyMemory ByVal pntrICE, dwBuffer, 4
              
                DoEvents
              
             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
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-11-18 12:44:13 | 显示全部楼层
原帖由 szdan 于 2008-11-18 11:27 发表
试试:

DeleteUrlCacheEntry URL


效率太低了~~~直接卡住。。。。
回复 支持 反对

使用道具 举报

发表于 2008-11-18 13:35:40 | 显示全部楼层

1

1
回复 支持 反对

使用道具 举报

发表于 2008-11-18 13:42:53 | 显示全部楼层
直接dir文件夹
删除就可以了
全部删除了
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-11-18 13:44:25 | 显示全部楼层
原帖由 szdan 于 2008-11-18 11:27 发表
试试:

DeleteUrlCacheEntry URL


这些函数只有时才可用使用 Microsoft Internet Explorer 5.........
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-11-18 13:44:43 | 显示全部楼层
原帖由 gujin162 于 2008-11-18 13:42 发表
直接dir文件夹
删除就可以了
全部删除了


权限不够~?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-11-18 14:06:06 | 显示全部楼层
继续顶,如何删除Temporary Internet Files下所有内容?即清空IE缓存

不能用的方法:
1~KILL的方式会报错,系统隐藏文件怎么kill
2~调用批处理del 也不能删
3~看了msdn这个
http://support.microsoft.com/default.aspx?scid=kb;en-us;311289
API貌似一样不能

4~FSO 也不行,权限的问题,很多系统都禁用FSO。

怎么删啊?。。。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-11-18 14:36:22 | 显示全部楼层
删除Cookies还是容易

Private Sub Command1_Click()
Dim sPath As String, sFile As String
sPath = Environ("USERPROFILE") & "\Cookies\"
sFile = Dir(sPath & "*.txt")
Do While sFile <> ""
        Kill sPath & sFile
        sFile = Dir
Loop
End Sub


但删除IE缓存就是个技术活了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

文字版|手机版|小黑屋|VBGood  

GMT+8, 2022-7-4 05:36

VB爱好者乐园(VBGood)
快速回复 返回顶部 返回列表