Question

  • Creator
    Topic
  • #2168670

    Batch File to delete cookies

    Locked

    by detroitreds ·

    I’m looking at creating a batch file to delete cookies and temp files from a remote computer. So in other words, I would manually map a drive to a computer, with the Z:\ drive for instance, and have the batch file delete cookies and temp files to all profiles within that Z:\ drive. Some computers have over 100 profiles, so you can see why a batch file would be useful. We’re in a Windows XP environment.

All Answers

  • Author
    Replies
    • #2779073

      Clarifications

      by detroitreds ·

      In reply to Batch File to delete cookies

      Clarifications

    • #2779064

      Try this

      by unhappyuser ·

      In reply to Batch File to delete cookies

      Go to this link and scroll down to the Accepted Solution. It’s VERY long! Good luck!

      http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Windows/2000/Q_20794666.html

      EMD

      • #2779041

        Account

        by detroitreds ·

        In reply to Try this

        I don’t have an account with them, but thanks anyways.

        • #2779038

          none needed

          by unhappyuser ·

          In reply to Account

          You don’t need one. If you scroll down far enough the solution is visible.

          EMD

        • #2779031

          I don’t see it

          by detroitreds ·

          In reply to none needed

          I’m looking at the page. I see about 30 replies and 1 accepted. no matter which one I choose, it’s asking to create an account. The page itself isn’t that long. I must be missing something.

        • #2779027

          Here it is

          by unhappyuser ·

          In reply to I don’t see it

          OK try

          Delete Cookies\Temp Internet, using VB (don’t panic its easy!)

          source: http://support.microsoft.com/default.aspx?scid=KB;en-us;q262110

          Paste the text below (not the ****) into notepad and save as “delete.vbs”
          Then simply run the file

          ****************************************************************************************************88
          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
          *************************************************************************************

    • #2779062

      Bat Fille

      by wizard-09 ·

      In reply to Batch File to delete cookies

      @echo off

      del /Q /F “%USERPROFILE%\Cookies\*.txt”
      del /Q /F “%USERPROFILE%\LocalSettings\Temp\*.*

      goto

      :end

      Edited for mistake made on temp file del

      tested now works

      Keep us informed as to your progress if you require further assistance.

      If you think that any of the posts that have been made by all TR Members, have solved or contributed to solving the problem, please Mark them as Helpful so that others may benefit from the outcome.

      • #2779050

        Question

        by unhappyuser ·

        In reply to Bat Fille

        This appears to only delete files in one profile. How does it delete the files in many, which I think is what they asked for?

        EMD

        • #2779048

          Because

          by wizard-09 ·

          In reply to Question

          If he was to add this to a shutdown script on AD then it will run for every user logged onto that OU when they shut down the machine.

        • #2779043

          Not realy what I’m looking for

          by detroitreds ·

          In reply to Because

          Although this might might work in AD, I’m looking at running it from a local computer. This script would only work for local profiles on the computer it’s ran from. Basically, I’m looking at saving time from having to open every profile on a mapped drive and deleting the said files.

        • #2779042

          Makes sense

          by unhappyuser ·

          In reply to Because

          I assumed he wanted to remove the files from all profiles in one quick script. Thanks.

          EMD

        • #2779039

          Well

          by wizard-09 ·

          In reply to Makes sense

          This would work on AD if the script was added to AD so i think he did get what he was looking for, as he only wants this for the local machine i will go back to the drawing board

        • #2779032

          Bat File New

          by wizard-09 ·

          In reply to Well

          echo off
          cd /d “%AllUsersProfile%\..”
          set Docs=%CD%
          for /d %%a in (*.*) do call :Del %%a
          goto :eof

          :Del
          echo Cleaning up user “%*”
          echo rd /s /q “%Docs%\%*\Cookies”
          echo md /s /q “%Docs%\%*\Cookies”

          echo rd /s /q “%Docs%\%*\Local Settings\Temporary Internet Files”
          echo md /s /q “%Docs%\%*\Local Settings\Temporary Internet Files”

          echo rd /s /q “%Docs%\%*\Local Settings\Temp”
          echo md /s /q “%Docs%\%*\Local Settings\Temp”

          I think this is the one your looking for 😛

        • #2779026

          looks good….

          by —tk— ·

          In reply to Bat File New

          I have to save that one… 🙂

        • #2779025

          I appreciate it

          by detroitreds ·

          In reply to Bat File New

          I appreciate your help, but it again cleans the files on the local C: drive. I have a batch file that does that already.

          For example, let’s say I manually map a drive or do net use z: \\computer name\c$, I’m looking at cleaning within that Z drive.

        • #2778937

          Can you combine

          by detroitreds ·

          In reply to Bat File New

          I actually like your idea to delete and create the folder. This would obviously make it faster. Would you be able to implement it with the following. This deletes each file seperatly. I would appreciate it if you could incorporate yours with this one:

          D:\documents and settings is where I would put in the mappped drive folder I want the batch file to point to.

          ————————————

          @echo
          off
          Set profileroot=d:\documents and settings

          FOR /F “tokens=*” %%I IN (‘DIR /B /AD “%profileroot%”‘) DO (
          echo del /s /q “%profileroot%\%%I\Cookies\*”
          echo del /s /q “%profileroot%\%%I\Local Settings\Temporary Internet Files\*”
          echo del /s /q “%profileroot%\%%I\Local Settings\Temp\*”
          )
          ————————————

    • #2779046

      would ccleaner help?

      by snuffy09 ·

      In reply to Batch File to delete cookies

      you can map your own custom folder to “clean up”

      or install on those computers

      http://www.ccleaner.com

      • #2779030

        Mapped drive option?

        by detroitreds ·

        In reply to would ccleaner help?

        I don’t see an option that it would delete on mapped drives, so I would assume this is only for the local C: drive

        • #2779021

          Ok

          by wizard-09 ·

          In reply to Mapped drive option?

          I dont no way you are going to all that trouble, that bat file the new one will del every cookie temp file on all the profiles on that computer right, so way not use add this to the shutdown script thats the easy way to do it, i really dont have time to recreate another bat file for what you asked looks like to much work will be involved which i dont have as i am working at the min, but if you add that new bat file to the shutdown script it will do what your wanting really :p

        • #2779018

          indeed there is an ooption

          by snuffy09 ·

          In reply to Mapped drive option?

          options>include>add folder

          if you have the drive mapped you can select the folder you want to clean out

    • #2779006

      Try this

      by bizzo ·

      In reply to Batch File to delete cookies

      Change the value of profile root to whatever location the user profiles are in.

      Also, remove the echos, just there for testing.

      But please make sure it deletes only what you want deleting BEFORE removing the echos!

      ————————————

      @echo
      off
      Set profileroot=d:\documents and settings

      FOR /F “tokens=*” %%I IN (‘DIR /B /AD “%profileroot%”‘) DO (
      echo del /s /q “%profileroot%\%%I\Cookies\*”
      echo del /s /q “%profileroot%\%%I\Local Settings\Temporary Internet Files\*”
      echo del /s /q “%profileroot%\%%I\Local Settings\Temp\*”
      )
      ————————————

      • #2778961

        Thanks

        by detroitreds ·

        In reply to Try this

        Thanks, it’s exactly what I was looking for.

Viewing 4 reply threads