Results 1 to 5 of 5

Thread: Cookies And Me!

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Boulder, Colorado, USA
    Posts
    325
    Anyone know how to list and/or delete cookies using VB?
    -Shickadance

  2. #2
    Member
    Join Date
    Apr 2001
    Location
    Los Angeles
    Posts
    45
    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

  3. #3
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    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

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  4. #4
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    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

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  5. #5
    Member
    Join Date
    Apr 2001
    Location
    Los Angeles
    Posts
    45
    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
  •  



Click Here to Expand Forum to Full Width