VB清除IE缓存

在窗体里放一个command控件,然后点击,就可以清除了: 

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
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
VB.NET中清空Excel缓存可以通过以下步骤实现: 1. 首先,你需要引用Microsoft.Office.Interop.Excel命名空间,以便能够使用Excel相关的类和方法。 2. 创建一个Excel应用程序对象,并打开要操作的Excel文件。 3. 获取Excel应用程序对象的Workbooks集合,并通过索引或名称获取要操作的Workbook对象。 4. 获取Workbook对象的Worksheets集合,并通过索引或名称获取要操作的Worksheet对象。 5. 使用Worksheet对象的Cells属性获取单元格范围。 6. 使用Range对象的Clear方法清空单元格范围的内容。 7. 最后,关闭Excel应用程序对象并释放相关资源。 下面是一个示例代码,演示了如何在VB.NET中清空Excel缓存: ```vb.net Imports Microsoft.Office.Interop.Excel Public Sub ClearExcelCache(ByVal filePath As String) Dim excelApp As New Application() Dim workbook As Workbook = excelApp.Workbooks.Open(filePath) Dim worksheet As Worksheet = workbook.Worksheets(1) Dim range As Range = worksheet.Cells range.Clear() workbook.Close(SaveChanges:=True) excelApp.Quit() ReleaseObject(worksheet) ReleaseObject(workbook) ReleaseObject(excelApp) End Sub Private Sub ReleaseObject(ByVal obj As Object) Try System.Runtime.InteropServices.Marshal.ReleaseComObject(obj) obj = Nothing Catch ex As Exception obj = Nothing Finally GC.Collect() End Try End Sub ``` 请注意,上述代码中的ReleaseObject方法用于释放COM对象的资源,以避免内存泄漏。在使用完COM对象后,应该调用ReleaseObject方法释放资源。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值