Question
-
CreatorTopic
-
March 5, 2009 at 4:57 am #2168670
Batch File to delete cookies
Lockedby detroitreds · about 15 years ago
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.
Topic is locked -
CreatorTopic
All Answers
-
AuthorReplies
-
-
March 5, 2009 at 4:57 am #2779073
Clarifications
by detroitreds · about 15 years ago
In reply to Batch File to delete cookies
Clarifications
-
March 5, 2009 at 5:35 am #2779064
Try this
by unhappyuser · about 15 years ago
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
-
March 5, 2009 at 6:44 am #2779041
Account
by detroitreds · about 15 years ago
In reply to Try this
I don’t have an account with them, but thanks anyways.
-
March 5, 2009 at 6:47 am #2779038
none needed
by unhappyuser · about 15 years ago
In reply to Account
You don’t need one. If you scroll down far enough the solution is visible.
EMD
-
March 5, 2009 at 6:55 am #2779031
I don’t see it
by detroitreds · about 15 years ago
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.
-
March 5, 2009 at 7:01 am #2779027
Here it is
by unhappyuser · about 15 years ago
In reply to I don’t see it
OK try
Delete Cookies\Temp Internet, using VB (dont 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 ExplicitPrivate 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 LongPrivate Declare Function FindNextUrlCacheGroup Lib “wininet.dll” ( _
ByVal hFind As Long, _
ByRef lpGroupId As Date, _
ByRef lpReserved As Long) As LongPrivate Declare Function DeleteUrlCacheGroup Lib “wininet.dll” ( _
ByVal sGroupID As Date, _
ByVal dwFlags As Long, _
ByRef lpReserved As Long) As LongPrivate Declare Function FindFirstUrlCacheEntry Lib “wininet.dll” Alias “FindFirstUrlCacheEntryA” ( _
ByVal lpszUrlSearchPattern As String, _
ByRef lpFirstCacheEntryInfo As INTERNET_CACHE_ENTRY_INFO, _
ByRef lpdwFirstCacheEntryInfoBufferSize As Long) As LongPrivate Type INTERNET_CACHE_ENTRY_INFO
dwStructSize As Long
szRestOfData(1024) As Long
End TypePrivate Declare Function DeleteUrlCacheEntry Lib “wininet.dll” Alias “DeleteUrlCacheEntryA” ( _
ByVal lpszUrlName As Long) As LongPrivate Declare Function FindNextUrlCacheEntry Lib “wininet.dll” Alias “FindNextUrlCacheEntryA” ( _
ByVal hEnumHandle As Long, _
ByRef lpNextCacheEntryInfo As INTERNET_CACHE_ENTRY_INFO, _
ByRef lpdwNextCacheEntryInfoBufferSize As Long) As LongPrivate 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 = 2048Private 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 LongOn 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 IfIf (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
*************************************************************************************
-
-
-
March 5, 2009 at 5:38 am #2779062
Bat Fille
by wizard-09 · about 15 years ago
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.
-
March 5, 2009 at 6:27 am #2779050
Question
by unhappyuser · about 15 years ago
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
-
March 5, 2009 at 6:36 am #2779048
-
March 5, 2009 at 6:43 am #2779043
Not realy what I’m looking for
by detroitreds · about 15 years ago
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.
-
March 5, 2009 at 6:44 am #2779042
Makes sense
by unhappyuser · about 15 years ago
In reply to Because
I assumed he wanted to remove the files from all profiles in one quick script. Thanks.
EMD
-
March 5, 2009 at 6:47 am #2779039
Well
by wizard-09 · about 15 years ago
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
-
March 5, 2009 at 6:54 am #2779032
Bat File New
by wizard-09 · about 15 years ago
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 😛
-
March 5, 2009 at 7:07 am #2779026
-
March 5, 2009 at 7:10 am #2779025
I appreciate it
by detroitreds · about 15 years ago
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.
-
March 5, 2009 at 11:04 am #2778937
Can you combine
by detroitreds · about 15 years ago
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 settingsFOR /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\*”
)
————————————
-
-
-
March 5, 2009 at 6:37 am #2779046
would ccleaner help?
by snuffy09 · about 15 years ago
In reply to Batch File to delete cookies
you can map your own custom folder to “clean up”
or install on those computers
-
March 5, 2009 at 6:57 am #2779030
Mapped drive option?
by detroitreds · about 15 years ago
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
-
March 5, 2009 at 7:17 am #2779021
Ok
by wizard-09 · about 15 years ago
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
-
March 5, 2009 at 7:21 am #2779018
indeed there is an ooption
by snuffy09 · about 15 years ago
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
-
-
-
March 5, 2009 at 7:49 am #2779006
Try this
by bizzo · about 15 years ago
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 settingsFOR /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\*”
)
————————————-
March 5, 2009 at 9:58 am #2778961
Thanks
by detroitreds · about 15 years ago
In reply to Try this
Thanks, it’s exactly what I was looking for.
-
-
-
AuthorReplies