|
-
May 24th, 2000, 09:46 AM
#1
Thread Starter
Hyperactive Member
Anyone know how to list and/or delete cookies using VB?
-
Apr 17th, 2001, 04:09 AM
#2
Member
Yes, I have created a program that allows the user to see a list of cookies and delete the ones they don't want.
Have a file list box and set the pattern to "*.txt". Then set the file list box's path to the cookie folder, usually "C:\WINDOWS\Cookies\". There is code around to get the folder path without hard coding it and getting it from the registry. Anyway, when a cookie is selected and the user hits delete, then in code say:
"Kill CookiePath & file.filename"
Were Cookiepath is the cookiepath and file is the name of the file list box.
Hope this helps
-
Apr 17th, 2001, 04:23 AM
#3
1) You need to find the windows directory first :
Code:
Private Declare Function GetWindowsDirectory Lib "kernel32" Alias _
"GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Sub Form_Load()
Dim WindowsDir As String, RetLength As Long
WindowsDir = Space(255)
RetLength = GetWindowsDirectory(WindowsDir, 255)
MsgBox "Windows Path is at : " & Left(WindowsDir, RetLength)
End Sub
2) You need to watch out for the INDEX.DAT file - this keeps a record of the number of cookies, kinda like a database held in the cookies folder (and doesn't like being deleted - it's possible, but we're just going to ignore this)!
3) The following deletes all txt files in the folder :
Code:
Private Declare Function GetWindowsDirectory Lib "kernel32" Alias _
"GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Sub Command1_Click()
Dim WindowsDir As String, RetLength As Long
WindowsDir = Space(255)
RetLength = GetWindowsDirectory(WindowsDir, 255)
WindowsDir = Left(WindowsDir, RetLength)
Kill WindowsDir & "\Cookies\*.txt"
End Sub
-
Apr 17th, 2001, 04:33 AM
#4
Okay, that was a quick workaround.
I haven't got any cookies at the moment from testing the above. Please try this one, and let us know if it doesn't work. You'll need a new project, with a command button and a filelistbox on the form :
Code:
Private Declare Function GetWindowsDirectory Lib "kernel32" Alias _
"GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Sub Command1_Click()
Dim WindowsDir As String, RetLength As Long
WindowsDir = Space(255)
RetLength = GetWindowsDirectory(WindowsDir, 255)
WindowsDir = Left(WindowsDir, RetLength)
Select Case Len(WindowsDir & "\Cookies\")
Case 0
'There are no files in the folder, ignore this
Case Else
File1.Path = WindowsDir & "\Cookies"
Dim ArrFileNames() As String
Dim i As Integer
For i = 0 To File1.ListCount - 1
If File1.FileName <> "index.dat" Then
With File1
.Index = i
ArrFileNames(i) = .FileName
End With
End If
Next i
'Check for an index.dat file, and add all the filenames to an array
Dim Filecount As Integer
For Filecount = 0 To UBound(ArrFileNames)
Kill WindowsDir & "\Cookies\" & ArrFileNames(Filecount)
Next i
'loop through all the filenames from the array & delete them
End Select
End Sub
-
Apr 20th, 2001, 11:55 AM
#5
Member
Here is a link to a better way of getting the cookie path.
http://forums.vb-world.net/showthrea...threadid=69476
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|