Solved

Batch file to delete temporary internet files and others

Posted on 2003-11-11
40
40,991 Views
Last Modified: 2011-10-03
I am trying to write an efficient batch file to do some cleanup for systems in our network prior to recreating new systems and copying some saved files over to the new computer.  

The following is what I am trying to clean up....
---------------------------------------------------------------------------------------------------------------
User Specific files:
C:\Documents and Settings\user\Local Settings\History
C:\Documents and Settings\user\Local Settings\Temp
C:\Documents and Settings\user\Local Settings\Temporary Internet Files\Content.IE5

General System files:
C:\WINNT\Temp
C:\WINNT\system32\spool\PRINTERS

--------------------------------------------------------------------------------------------------------------------------

I am having problems deleting the files from these two directories
C:\Documents and Settings\radams\Local Settings\History
C:\Documents and Settings\radams\Local Settings\Temp

I am looking to delete all files in these two folders for every person/profile on the system.  Some systems may have 5 or more profiles on them.

The following code works for everything else except these two folders.  What am I missing?

Any assistance would be appreciated.


----------------------------------------------------------------------
SET SRC1=C:\Documents and Settings
SET SRC2=Local Settings\Temporary Internet Files\Content.IE5
SET SRC3=Local Settings\History
SET SRC4=Local Settings\Temp


FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC2%\*.*") DO RMDIR /S /Q "%%Y"

del "C:\winnt\system32\spool\PRINTERS\*.*" /f /s /q
del "C:\winnt\temp\*.*" /f /s /q


exit
0
Comment
Question by:RDAdams
  • 16
  • 7
  • 5
  • +7
40 Comments
 
LVL 57

Expert Comment

by:Pete Long
ID: 9724859
0
 
LVL 17

Author Comment

by:RDAdams
ID: 9725041
Unfortunately this only works for the current user.  Not all profiles at once.  Thanks for the attempt though.
0
 
LVL 57

Accepted Solution

by:
Pete Long earned 50 total points
ID: 9725643
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
*************************************************************************************
0
 
LVL 17

Author Comment

by:RDAdams
ID: 9726219
Except that I don't want to delete cookies.

This might work.  I will take a look at it and see.
0
 
LVL 17

Author Comment

by:RDAdams
ID: 9741486
When I run this I get a VBS compilation error in line 3.

Any other ideas folks???
0
 
LVL 17

Author Comment

by:RDAdams
ID: 9743067
Ok, I was able to figure this one out.  Here is my own answer that works 99.5% There are a few small files that remain but I can live with them.  The last two lines with the DEL command deletes the files from History and Temp unless another program still has the files in use.  (Locked open)  

I ran this on a system with 30 users and approx 15 meg of junk files and deleted the unnecessary junk in less than two minutes.

Hope This helps everyone.  

We use Windows 2000 Pro in a domain with thousands of users and rebuild up to 100 computers each month.  
---------------------------------------------------------------------------------------------------------------------
SET SRC1=C:\Documents and Settings
SET SRC2=Local Settings\Temporary Internet Files\Content.IE5
SET SRC3=Local Settings\History
SET SRC4=Local Settings\Temp

FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC2%\*.*") DO RMDIR /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC3%\*.*") DO RMDIR /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC4%\*.*") DO RMDIR  /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR  %%Y IN ("%%X\%SRC3%\*.*") DO DEL /F /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR  %%Y IN ("%%X\%SRC4%\*.*") DO DEL /F /S /Q "%%Y"

exit
0
 
LVL 17

Author Comment

by:RDAdams
ID: 9743075
Thanks for your ideas Petelong.  You certainly assisted in jogging my memory.
0
 
LVL 57

Expert Comment

by:Pete Long
ID: 9743274
Glad I could be of some help

Pete
0
 
LVL 17

Author Comment

by:RDAdams
ID: 9765323
Thanks again PeteLong.  I had the moderators change the points and give to you to acknowledge the help received.  Hope that is acceptable to you.
0
 

Expert Comment

by:manch03
ID: 10372804
When you say you ran this file - from a command prompt?  Or do you run it?
0
 

Expert Comment

by:Jimbob60
ID: 10949144
Here is a slightly expanded version of RDAdams's script, removes files from WINNT\temp and [Profilename]\Recent too.

@ECHO OFF
SET SRC1=C:\Documents and Settings
SET SRC2=Local Settings\Temporary Internet Files\Content.IE5
SET SRC3=Local Settings\History
SET SRC4=Local Settings\Temp
SET SRC5=Recent
echo About to delete files from Internet Explorer "Temporary Internet files"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC2%\*.*") DO RMDIR /S /Q "%%Y"
echo About to delete files from Internet Explorer "History"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC3%\*.*") DO RMDIR /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR  %%Y IN ("%%X\%SRC3%\*.*") DO DEL /F /S /Q "%%Y"
echo About to delete files from "Local settings\temp"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC4%\*.*") DO RMDIR  /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR  %%Y IN ("%%X\%SRC4%\*.*") DO DEL /F /S /Q "%%Y"
echo About to delete files from "Recent" i.e. what appears in Start/Documents/My Documents
FOR /D %%X IN ("%SRC1%\*") DO FOR  %%Y IN ("%%X\%SRC5%\*.lnk") DO DEL /F /S /Q "%%Y"
echo About to delete files from "Windows\Temp"
cd /d %SystemRoot%\temp
del /F /Q *.*
@echo Y|RD /S ""
exit
0
 
LVL 17

Author Comment

by:RDAdams
ID: 10949213
Hi manch03 sorry for not responding earlier.  Take the information for the script and put in in notepad and save as namex.bat then within windows Start > Run > namex.bat to run the file.  

Hi Jimbob60, the reason we didn't include the winnt\temp and profile recent in our batch file is some programs put information there we did not want to remove.  Custom programs our company developed.  But for most applications this is a good addition.

Thanks
0
 

Expert Comment

by:manch03
ID: 10949730
Would running this script in a user login policy on AD prevent BGinfo from saving to the local temp directory?  I have been receiving a bginfo error - which I posted in another question, but just curious if they are related.
0
 
LVL 17

Author Comment

by:RDAdams
ID: 10949784
After reading your question I would ask you to see if the file exists in the directory on the target computer first.  You don't have to log onto the computer to check this.  Use another computer and just open the c drive using start > run > \\targetcomputername\c$ then browse to the directory in question and see what files are there.  If it is then running the script would probably eliminate the error.  A more direct way to eliminate just this one file would be to add the script to remove just that one file that is causing the problems.  This would speed up the execution of your AD login script.
0
 

Expert Comment

by:Guda
ID: 11229056
Ok... sorry for attaching myself after all the work you guys did.   Not sure if I should even post here but my question is similar to RDAdams.  

I am trying to delete cached profiles on multiple W2K systems that have hundreds of users within a few months.  We have restrictive roaming profiles but there is still enough data being stored that the hard-drives are filling up too frequently.  The users are informed and save the majority of their data on server shares.  I need a script or batch file that will allow me to delete profiles that are ... say over 2 weeks old.  I realize GP would do this but it would take several months and many pulled teeth to accomplish.  Any suggestions... i am very novice when it comes to this.  Let me know if i need to post a new topic in order to award points.

thanks
0
 

Expert Comment

by:Guda
ID: 11229062
task manager... could i apply a script using task manager? or batch file?
0
 

Expert Comment

by:CSCfermoy
ID: 11752152
Hi there,
 
I have been searching for this for ages.
Servicing XP machines with multiple profiles is a real pain for us,  but I was just wondering if you could explain to me what is actualy happening in one line in the batch file.
I have a fairly good knowledge of Batch files and some knowledge of using variables.
 
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC2%\*.*") DO RMDIR /S /Q "%%Y"
 
1. What is the  "FOR /D %%X IN " doing exactly
2. Why is this there a Y and not an X like at the start here "DO FOR /D %%Y IN"
3. The /Q at the end I assume is not asking for confirmation
 
If you can answer these that we be great thanks
 
Mark
0
 

Expert Comment

by:jonnydd
ID: 11768766
In regards to your questions:

1. What is the  "FOR /D %%X IN " doing exactly - It conditionally performs a command on several folders versus the "FOR" command which runs a specified command for each file in a set of files.
2. Thre are two variables being used in the batchfile, hence %%x and %%y.
3. The /Q switch is for Quiet mode. Using it means you will do not have to give a Yes/No Prompt before deleting.  

Here is my question, I created a simpler version of this, which I listed below.  It runs fine from the command line, but I f I try to execute it using the Task Scheduler, I receive the following error: Result: The task completed with an exit code of (3).   I am using the local system account to operate the Task Scheduler Service and a Domain Admin account that has local Admin access to the particular test machine. Any ideas?  Thanks in advance!

@ECHO OFF
SET SRC1=C:\Documents and Settings
SET SRC2=Local Settings\Temporary Internet Files\Content.IE5
SET SRC3=Local Settings\Temp
echo About to delete files from Internet Explorer "Temporary Internet files"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC2%\*.*") DO RMDIR /S /Q "%%Y"
echo About to delete files from "Local settings\temp"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC3%\*.*") DO RMDIR  /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR  %%Y IN ("%%X\%SRC3%\*.*") DO DEL /F /S /Q "%%Y"
echo About to delete files from "Windows\Temp"
cd /d %SystemRoot%\temp
del /F /Q *.*
@echo Y|RD /S ""
exit
0
 
LVL 17

Author Comment

by:RDAdams
ID: 11773804
jonnydd

I always run this using the local administrator account.  It works great on windows 2000 and XP.  Don't setup using a domain account it isn't necessary.
0
 

Expert Comment

by:jonnydd
ID: 11776328
Thanks RD - I changed to the local admin account and it ran flawlessly.  Any Idea why the Doamin admin account which is also a local admin on all computers would not work?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 17

Author Comment

by:RDAdams
ID: 11776626
Still not sure but have encountered other similar issues when trying to run programs automatically as a Domain Admin instead of local.
0
 

Expert Comment

by:CSCfermoy
ID: 11843021
Hi Guys,
Can any one tell me where I can find a list of XP variable (like %SystemRoot% for c:\windows ?)
Many thanks to Jonnydd and RDAdams for the batch file but the problem is that
1. the batch file is hard coded to set the variable one to be C:\Documents and Settings.
         Many machines come into us with XP running from D:\  (don't ask me why)
2. I copied the batch file to a floppy and tried to run it on another machine from the floppy, the batch file ran and finished with  
    no errors but when I went to look at the floppy it was empty.
         Again the batch file starts runing from where ever you opened the file from, if you run the batch file from your C: then it is ok but I started the batch file from the floppy and so it skipped the first 4 lines of the code because those directories didn't exist on the A:  and then del /F /Q *.*

I want a %variable% that goes to where windows is installed (ie. c: if windows is on c drive d: if windows is on d drive etc)
that i can put in instead of C:\Documents and Settings in the 2nd line and then also bfore starting to delete any files change to that drive so i can run it from a floppy?

Cheers
Mark
0
 
LVL 57

Expert Comment

by:Pete Long
ID: 11843041
right click my computer >properties >advanced >enviroment variables
0
 
LVL 57

Expert Comment

by:Pete Long
ID: 11843059
0
 

Expert Comment

by:CSCfermoy
ID: 11843156
tried that couldn't see the variable for th system dive ?
0
 

Expert Comment

by:CSCfermoy
ID: 11843272
I need a variable that just returns the value of the drive which windows is installed on ie c:\ or d:\

PS thanks to PeterLong great page :-)

Mark
0
 
LVL 17

Author Comment

by:RDAdams
ID: 11843580
How about adding a IF statement to see if C:\Documents and Settings exists, duplicate

IF EXIST D:\Documents and Settings GOTO ALTDrive


SET SRC1=C:\Documents and Settings
SET SRC2=Local Settings\Temporary Internet Files\Content.IE5
SET SRC3=Local Settings\History
SET SRC4=Local Settings\Temp

FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC2%\*.*") DO RMDIR /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC3%\*.*") DO RMDIR /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC4%\*.*") DO RMDIR  /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR  %%Y IN ("%%X\%SRC3%\*.*") DO DEL /F /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR  %%Y IN ("%%X\%SRC4%\*.*") DO DEL /F /S /Q "%%Y"

exit

ALTDrive

SET SRC1=D:\Documents and Settings
SET SRC2=Local Settings\Temporary Internet Files\Content.IE5
SET SRC3=Local Settings\History
SET SRC4=Local Settings\Temp

FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC2%\*.*") DO RMDIR /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC3%\*.*") DO RMDIR /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC4%\*.*") DO RMDIR  /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR  %%Y IN ("%%X\%SRC3%\*.*") DO DEL /F /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR  %%Y IN ("%%X\%SRC4%\*.*") DO DEL /F /S /Q "%%Y"

exit
0
 
LVL 17

Author Comment

by:RDAdams
ID: 11843618
Not sure if you need quotes arount the string but it might work.
0
 

Expert Comment

by:CSCfermoy
ID: 11843990
Yea i suppose that would work, I think i've only ever had one person in with XP running from E drive but it does happen.

The problem is we are running a computer service centre and we get a lot of people who have tried to fix thier computer by sticking in the windows cd. All that ends up happening is they get one bootable version on C: and one bootable version on D: this happens alot for us.

The problem with the IF statement is that there would be a c:\docs and settings but it wouldn't necesarily be the one that was being used?

Sorry if that doesn't make sence have been trying to get this working 4 a few days along with single click reg file that sets everything up [the way it should have been by default :-; ] and the other batch files for instlling software and updating on all existing profiles from a single click (have gone boggle eyed now my stomach and brain are telling me to unplug for a bit)

I found that runing the %HOMEDRIVE% returns me back c:\> on my PC hich i what I want but I think if I use that in a batch file and I use it on a business machine which has the %HOMEDRIVE% set to a share on a server I could really do damage,
Also running %HOMEPATH% gave me c:\Documents and settings\mark> which is almost the correct thing, again would be worried if this had been set to a network share!!!

Any way going to rest my bones now,  Will check in inthe morning to see if any one has found anyting,

Thanks again
Mark
0
 
LVL 17

Author Comment

by:RDAdams
ID: 11844014
I guess this is a good reason to always setup each computer the same way.  I work in an environment with over 1000 computers.  We could never accomplish tasks efficiently without using the same setup on every computer for the base software.
0
 

Expert Comment

by:CSCfermoy
ID: 11844071
You are so lucky :-)

I have to deal with "The General Public"
the only control I have over thier machines is when I delete it set it up properly and then charge them for it, unfotunatly can't do this to all those customers who just wan't a virus or spyware removed.

Mark
0
 
LVL 17

Author Comment

by:RDAdams
ID: 11844173
You can however tell them they have a non-standard setup on their computer which will cost them more to maintain.  Charge them in where they notice, the pocket book.  

An extra $25.00 or more each time extra may convince them to have you make their computer standard.

Good luck Mark.
0
 

Expert Comment

by:BenEdwards
ID: 12273470
How do I get the batch file to delete cookies as well?
Something like
SET SRC5=%username%\Local Settings\Temporary Internet Files
can't seem to get the syntax correct.

Thanks for the help
0
 
LVL 17

Author Comment

by:RDAdams
ID: 12275652
Hello Ben, try the following.  SRC5 directory
and new line in action statements to act on SRC5 (see the ninth line)
______________________________________________________________________________________
SET SRC1=C:\Documents and Settings
SET SRC2=Local Settings\Temporary Internet Files\Content.IE5
SET SRC3=Local Settings\History
SET SRC4=Local Settings\Temp
SET SRC5=Local Settings

FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC2%\*.*") DO RMDIR /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC3%\*.*") DO RMDIR /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC4%\*.*") DO RMDIR  /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC5%\*.*") DO RMDIR  /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR  %%Y IN ("%%X\%SRC3%\*.*") DO DEL /F /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR  %%Y IN ("%%X\%SRC4%\*.*") DO DEL /F /S /Q "%%Y"

exit
0
 

Expert Comment

by:CSCfermoy
ID: 12275920
Hi Guys,
Got this one sorted with system variables :-) and when run on XP and 2000 will clean all profiles at once.
You cannot batch delete content.ie5 for the profile that you are logged into we get around this by booting in safe mode and logging in as administrator

Copy and past into notepad and save as a batch file.
Remember the confirmation Y is case sensative. (sorry about the long post could see how to post with attachment)

***************************************************************************
cls
@echo off
:start
cls  
@ECHO.
@ECHO.
@ECHO.
@ECHO            ********************************************************************
@ECHO            ****                                                ****
@ECHO            ****      PLEASE CHECK TO SEE IF THIS IS YOUR SYSTEM DRIVE      ****
@ECHO            ****                                                ****
@ECHO            ****                                                ****
@ECHO            ****                                                ****
@ECHO            ****            --      %HOMEDRIVE%      --                        ****
@ECHO            ****                                                ****
@ECHO            ****      This is intended for NT based systems ONLY            ****
@ECHO            ****                                                ****
@ECHO            ********************************************************************
@ECHO.
@ECHO.
@ECHO.
set choice=
set /p choice=Type Y or N to continue:
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='Y' goto clean2
if '%choice%'=='N' goto bye
@ECHO " %choice% " is not valid please try again (Y or N are case sensative)
@ECHO.
@echo.
PAUSE
goto start            

:clean2
cls
SET SRC1=%SYSTEMDRIVE%\Documents and Settings
SET SRC2=Local Settings\Temporary Internet Files\Content.IE5
SET SRC3=Local Settings\Temp
echo About to delete files from Internet Explorer "Temporary Internet files"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC2%\*.*") DO RMDIR /S /Q "%%Y"
echo About to delete files from "Local settings\temp"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC3%\*.*") DO RMDIR  /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR  %%Y IN ("%%X\%SRC3%\*.*") DO DEL /F /S /Q "%%Y"
echo About to delete files from "Windows\Temp"
cd\
%systemdrive%
cd /d %SystemRoot%\temp
del /F /Q *.*
@echo Y|RD /S ""
@echo.
@echo.
@echo            Please review any errors if they exist
@echo.
@echo.
PAUSE
goto end

:clean
cls
SET drive=%SYSTEMDRIVE%
SET SRC1=%drive%\Documents and Settings
SET SRC2=Local Settings\Temporary Internet Files
SET SRC3=Local Settings\History
SET SRC4=Local Settings\Temp
SET SRC5=%SYSTEMROOT%\Temp
@echo.
@echo.
@echo             About to delete Temporary Internet Files
@echo.
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC2%\*.*") DO RMDIR /S /Q "%%Y"
@echo.
@echo            About to delete History
@echo.
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC3%\*.*") DO RMDIR /S /Q "%%Y"
@echo.
@echo            About to delete Temp
@echo.
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC4%\*.*") DO RMDIR  /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR  %%Y IN ("%%X\%SRC3%\*.*") DO DEL /F /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR  %%Y IN ("%%X\%SRC4%\*.*") DO DEL /F /S /Q "%%Y"
@echo.
@echo            About to delete System Temp
cd\
%systemdrive%
cd %SRC5%
del /F /Q *.*

@echo.
@echo.
@echo            Please review any errors if they exist
@echo.
@echo.
PAUSE
goto end

:bye
cls
@echo.
@echo.
@echo            **********You have chosen to exit the batch file**********
@echo            Please check on which drive Documents and Settings resides
@echo            **********************************************************
@echo.
@echo.
Pause
goto end

:end
cls
****************************************************************************************
0
 
LVL 17

Author Comment

by:RDAdams
ID: 12275950
Just as a note, I think that if others have additional questions to pose on this they should create a new question and award points for it.  This has been closed for some time now.
0
 

Expert Comment

by:BenEdwards
ID: 12276681
Thanks RDAdams, that worked. I appreciate the help.
0
 

Expert Comment

by:Jimbob60
ID: 13496626
Just a quick note to RDAdams regarding clearing out Cookies using his method posted on 10/11/2004 05:35AM PDT:

SET SRC5=Local Settings
and
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC5%\*.*") DO RMDIR  /S /Q "%%Y"

This removed the temp directory from "C:\Documents and Settings\[username]\Local Settings\Temp" on my Windows 2000 PC (and did not delete the cookies).

I replaced the two lines with

SET SRC5=Cookies

and

FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC5%\*.txt") DO DEL /F /S /Q "%%Y"

This cleared out the Cookies correctly.
0
 

Expert Comment

by:maheshkolvankar
ID: 24743026
IT's Working we added below things in Batch Files

---------------------------------------------------------------------------------

cls
SET SRC1=%SYSTEMDRIVE%\Documents and Settings
SET SRC2=Local Settings\Temporary Internet Files\Content.IE5
SET SRC3=Local Settings\Temp
SET SRC4=Local Settings\History
SET SRC5=%SYSTEMROOT%\Temp
SET SRC6=Cookies


echo About to delete files from Internet Explorer "Temporary Internet files"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC2%\*.*") DO RMDIR /S /Q "%%Y"
echo About to delete files from "Local settings\temp"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC3%\*.*") DO RMDIR  /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR  %%Y IN ("%%X\%SRC3%\*.*") DO DEL /F /S /Q "%%Y"
echo About to delete files from "Windows\Temp"
cd\
%systemdrive%
cd /d %SystemRoot%\temp
del /F /Q *.*
@echo Y|RD /S ""
@echo.
@echo.
echo About to delete files from "Local Settings\History"
FOR /D %%X IN ("%SRC1%\*") DO FOR  %%Y IN ("%%X\%SRC4%\*.*") DO DEL /F /S /Q "%%Y"

FOR /D %%X IN ("%SRC1%\*") DO FOR  %%Y IN ("%%X\%SRC4%\today*.*") DO DEL /F /S /Q "%%Y"

FOR /D %%X IN ("%SRC1%\*") DO FOR  %%Y IN ("%%X\%SRC4%\*.*") DO DEL /F /S /Q "%%Y"

echo About to delete files from "%SYSTEMROOT%\Temp"
FOR /D %%X IN ("%SRC1%\*") DO FOR  %%Y IN ("%%X\%SRC5%\*.*") DO DEL /F /S /Q "%%Y"

echo About to delete files from "Cookies"
FOR /D %%X IN ("%SRC1%\*") DO FOR  %%Y IN ("%%X\%SRC6%\*.*") DO DEL /F /S /Q "%%Y"

@echo            Please review any errors if they exist
@echo.
@echo.



----------------------------------------------------------------------------------------------------



0
 
LVL 7

Expert Comment

by:CitizenRon
ID: 25101486
This section is a bit redundant:

echo About to delete files from "%SYSTEMROOT%\Temp"
FOR /D %%X IN ("%SRC1%\*") DO FOR  %%Y IN ("%%X\%SRC5%\*.*") DO DEL /F /S /Q "%%Y"


Basically, you're telling the computer:

"For Each Folder in 'C:\Documents and Settings', Delete all files in 'C:\Windows\Temp\*.*'"

So you're running the DEL command multiple times, depending on how many user profile folders are in the Docs and Settings folder.

Also, since it's just the one folder you're deleting from, can't you just get rid of the FOR/DO loop altogether?  Like this:

DEL %SYSTEMROOT%\Temp\*.* /F /S /Q

Or am I missing something obvious?
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now