附件为工程文件
Imports System.Runtime.InteropServices
Public Class Form1
Private Const NO_ERROR As Integer = 0
Private Const INTERNET_OPTION_END_BROWSER_SESSION As Integer = 42
Private Const CSIDL_COOKIES As Integer = &H21
Private Structure SHITEMID
Public cb As Int32
Public abID As Byte
End Structure
Private Structure ITEMIDLIST
Public mkid As SHITEMID
End Structure
_
Private Shared Function SHGetSpecialFolderLocation( _
ByVal hwndOwner As IntPtr, _
ByVal nFolder As Int32, _
ByRef ppidl As ITEMIDLIST) As Boolean
End Function
_
Private Shared Function SHGetPathFromIDList( _
ByVal pidl As Int32, _
ByVal pszPath As System.Text.StringBuilder) As Boolean
End Function
_
Private Shared Function InternetSetOption( _
ByVal hInternet As IntPtr, _
ByVal dwOption As Int32, _
ByVal lpBuffer As IntPtr, _
ByVal dwBufferLength As Int32) As Boolean
End Function
Private Function GetSpecialfolder(ByVal CSIDL As Integer) As String
Dim r As Integer
Dim IDL As ITEMIDLIST
Dim path As New System.Text.StringBuilder(512)
'Get the special folder
r = SHGetSpecialFolderLocation(100, CSIDL, IDL)
If r = NO_ERROR Then
'Get the path from the IDList
r = SHGetPathFromIDList(IDL.mkid.cb, path)
End If
Return path.ToString()
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' 获取COOKIES文件夹路径
Dim CookiesPath As String = GetSpecialfolder(CSIDL_COOKIES)
MsgBox(CookiesPath & "A")
' 为了防止在ie打开时,内存中还有部分COOKIES存在,加了下面这句
Call InternetSetOption(0, INTERNET_OPTION_END_BROWSER_SESSION, IntPtr.Zero, 0)
'全部删除,如果需要删除某一个COOKIES的话,需要用dir或fso枚举出所有文件,然后用kill语句删除
Kill(CookiesPath + "\*.txt")
End Sub
End Class