问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

如何用VB定时删除cookie和ie的临时文件

发布网友 发布时间:2022-05-01 23:49

我来回答

2个回答

热心网友 时间:2022-06-25 06:13

清空IE缓存和Cookie
新增一个Form,新增一个ListBox,新增三个CommandButton,新增一个Label名称取默认值,粘贴下面代码到Form的代码窗口中,
定时的功能自己加一个定时器
摘自 http://vbnet.mvps.org/index.html?code/internet/deleteurlcache.htm
'该示例提供读取缓存列表,删除指定缓存,删除所有缓存

Option Explicit

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ??1996-2008 VBnet, Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
' applications, but you may not reproce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

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

Private Sub Form_Load()

Command1.Caption = "Get Cache"
Command2.Caption = "Delete Selected"
Command3.Caption = "Delete All"
Label1.Caption = ""

End Sub

Private Sub Form_Resize()

If Me.WindowState <> vbMinimized Then

If Me.Width > 3000 Then

With Command1
.Left = Me.ScaleWidth - .Width - 200
.Top = 200
End With

With Command2
.Left = Command1.Left
.Top = Command1.Top + Command1.Height + 100
End With

With Command3
.Left = Command1.Left
.Top = Command2.Top + Command2.Height + 100
End With

With Label1
.Left = 200
.Top = Me.ScaleHeight - 100 - Label1.Height
End With

With List1
.Left = 200
.Top = 200
.Width = Command1.Left - 300
.Height = (Me.ScaleHeight - 300) - (Me.ScaleHeight - Label1.Top)
End With

End If

End If

End Sub

Private Sub Command1_Click()

With List1

'this speeds up adding to the list
'and eliminates list flicker
.Visible = False
.Clear
Call GetCacheURLList
.Visible = True

Label1.Caption = .ListCount & " files listed."

End With

End Sub

Private Sub Command2_Click()

Dim cachefile As String
Dim currindex As Long
Dim currtopindex As Long

'delete the selected file
With List1

'because we're going to reload
'the cache following the deletion,
'be nice and save the current list
'position so it can be restored later
currtopindex = .TopIndex
currindex = .ListIndex
cachefile = .List(currindex)

Call DeleteUrlCacheEntry(cachefile)

'reload the list, hiding the list box
'to prevent flicker. (This workaround
'will not provided the desired results
'if a DoEvents is added to the
'GetCacheURLList routine!)

.Visible = False
GetCacheURLList
.TopIndex = currtopindex

If currindex >= .ListCount Then
.ListIndex = currindex - 1
Else
.ListIndex = currindex
End If

.Visible = True

Label1.Caption = .ListCount & " files listed."

End With

End Sub

Private Sub Command3_Click()

Dim cachefile As String
Dim cnt As Long

With List1

'delete all files
For cnt = 0 To .ListCount - 1

cachefile = .List(cnt)

'if the file is a cookie let's not
'delete it in case it is used to
'store password data.
'
'remove the Instr() test if you want
'to delete cookies as well
If InStr(cachefile, "Cookie") = 0 Then
Call DeleteUrlCacheEntry(cachefile)
End If
Next

.Visible = False
GetCacheURLList
.ListIndex = -1
.Visible = True

Label1.Caption = .ListCount & " files listed."

End With

End Sub

Private Sub List1_Click()

Command2.Enabled = InStr(List1.List(List1.ListIndex), "Cookie") = 0

End Sub

Private Sub GetCacheURLList()

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

List1.Clear

'Like other APIs, calling FindFirstUrlCacheEntry or
'FindNextUrlCacheEntry with an buffer of insufficient
'size will cause the API to fail. Call first to
'determine the required buffer size.
hFile = FindFirstUrlCacheEntry(0&, ByVal 0, dwBuffer)

'both conditions should be met by the first call
If (hFile = ERROR_CACHE_FIND_FAIL) And _
(Err.LastDllError = ERROR_INSUFFICIENT_BUFFER) Then

'The INTERNET_CACHE_ENTRY_INFO data type
'is a variable-length UDT. It is therefore
'necessary to allocate memory for the result
'of the call and to pass a pointer to this
'memory location to the API.
pntrICE = LocalAlloc(LMEM_FIXED, dwBuffer)

'allocation successful
If pntrICE <> 0 Then

'set a Long pointer to the memory location
CopyMemory ByVal pntrICE, dwBuffer, 4

'call FindFirstUrlCacheEntry again
'now passing the pointer to the
'allocated memory
hFile = FindFirstUrlCacheEntry(vbNullString, _
ByVal pntrICE, _
dwBuffer)

'hfile should = 1 (success)
If hFile <> ERROR_CACHE_FIND_FAIL Then

'loop through the cache
Do

'the pointer has been filled, so move the
'data back into a ICEI structure
CopyMemory icei, ByVal pntrICE, Len(icei)

'CacheEntryType is a long representing
'the type of entry returned
If (icei.CacheEntryType And _
NORMAL_CACHE_ENTRY) = NORMAL_CACHE_ENTRY Then

'extract the string from the memory location
'pointed to by the lpszSourceUrlName member
'and add to a list
cachefile = GetStrFromPtrA(icei.lpszSourceUrlName)
List1.AddItem cachefile

End If

'free the pointer and memory associated
'with the last-retrieved file
Call LocalFree(pntrICE)

'and again by repeating the procere but
'now calling FindNextUrlCacheEntry. Again,
'the buffer size set to 0 causing the call
'to fail and return the required size as dwBuffer
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

'and call again with the valid parameters.
'If the call fails (no more data), the loop exits.
'If the call is successful, the Do portion of the
'loop is executed again, extracting the data from
'the returned type
Loop While FindNextUrlCacheEntry(hFile, ByVal pntrICE, dwBuffer)

End If 'hFile

End If 'pntrICE

End If 'hFile

'clean up by closing the find handle,
'as well as calling LocalFree again
'to be safe
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

热心网友 时间:2022-06-25 06:14

timer1.interval=5000
timer1_timer()
kill cookie目录\*.*
end sub
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
鞋底是空心格子怎么办 鞋里有格子硌脚怎么办 买的鞋子里面是空心格子底硌脚怎么办 鞋子底是空心格子的怎样办 浅谈NY5196—2002有机茶 有机食品茶叶标准 茶叶的储藏运销:茶叶贮藏期的化学变化 东方美人茶要怎么储存?东方美人茶储存方法 乌龙茶贮运方法 有机乌龙茶是什么贮藏与运输的? 求高人翻译! 2K账号收验证码用谷歌邮箱会更快吗? 如何设置软件信任 2k22怎么验证邮箱 ASP.Net中防止页面刷新重复提交的几种方法 2k22体育账户怎么确认邮箱 flash取消右键菜单的方法 your nba 2k account has been verified. 昨天下载了一个2k12,一进去说是要注册,我就注册完了。但是一直没有收到那个2k账户的邮箱验证? jquery 用了e.preventDefault();阻止表单提交后如何解除e.preventDefault... 请问target=&quot;_blank&quot; 不打开新链接是这么做到的? vue.js 中 如何阻止默认事件,请给demo!!! 社会考生如何参加单招 普通高中应届生怎么报考单招? 我发现我还有一些权益未主张。我还能再申请仲裁吗?我该怎么做 做人是不是应该有自己的主张? 我有权主张两个沙地吗?若能,以什么理由比较合适? 谁推荐一些类似 我有我主张 这样的动画电影中的插曲 或有点音乐剧的感觉的歌 金莎 我有我主张 高品质CD 作文 我的读书主张 ............. 求暗黑破坏神2修改器udietoo汉化版下载 心电图以及心肌梗死的问题 怎么样使C盘点开时显示里面的“文件是隐藏的” NBA2k12 联网以前11的帐号还能用么?注册时有个邮箱怎么填?换了几个都提示无效 NBA2K12注册了个2K账户, 发来个邮箱,求翻译帝 2k22辉煌生涯怎么认证年龄 我昨天买盘安装了nba2k12的游戏,但一进去就让我注册密码邮箱什么的, 2k22自创球员账户失效 香菜这么难吃,为什么叫香菜? 芫荽都可以用来做什么菜啊? 各地的民风民俗说明文 为什么把鱿鱼叫做乌桐花? 香菜和臭屁虫科学解释 乌子炖豆腐放韭菜还是香菜? 手机连5gWiFi系统会不会耗电vivo手机系统耗电严重怎么办啊? 清明草孕妇可以吃吗 鼠曲草孕妇能吃吗 考研政治有何要求? 孕妇能吃鼠曲草吗 鼠曲草怎么吃 研究生升学考试政治对政治有要求吗,必须及格吗?