Question

Batch file to delete temporary internet files and others

Asked by: RDAdams

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

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2003-11-11 at 11:24:02ID20794666
Tags

files

,

delete

,

internet

,

temporary

,

batch

Topic

Windows 2000 Operating System

Participating Experts
9
Points
50
Comments
40

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. corrupt Content.IE5 file
    First, would like to thank all who answered last question of mine concerning hanging in safe mode. Finally got computer to run scandisk in safe mode but it still wanted to re-start all the time which led me to think that there must ne something wrong with explorer.exe since...
  2. How to delete printer files in winnt\system32\spool\PR…
    On my Windows 2000 server, I would like to know why the following folder gets filled up with printer files: Winnt\system32\spool\printers I couldn't figure out why my Main hard disk was losing disk space so fast. I was told I could make a batch file stopping the print spool...
  3. Windows\System32\config\content.IE5 folder
    I recently had some problems with my computer. I completed a system restore and after the restore was complete I noted that the system restore had renamed some files in the Windows\system32\config\systemprofile\content.IE5 folder. I went in and viewed the contents of this f...
  4. Deleting IIS logs in C:\WINNT\system32\LogFiles\W…
    Hi all, We currently have a system drive that is approaching capacity very rapidly. The space is being used by IIS log files being created in the following directory: C:\WINNT\system32\LogFiles\W3SVC1 Is there anyway to safely delete these logs and then prevent this from re...
  5. Content.IE5 in XP Pro
    Hello I was surfing the net this morning and my virus software found that "The file C:\Documents and Settings\user\Local Settings\Temporary Internet Files\Content.IE5\FA8VNH4H\606969[1].exe is infected with QLowZones-5 Trojan. I could not delete the file through my viru...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: RDAdamsPosted on 2003-11-11 at 11:49:14ID: 9725041

Unfortunately this only works for the current user.  Not all profiles at once.  Thanks for the attempt though.

 

by: PeteLongPosted on 2003-11-11 at 13:02:44ID: 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
*************************************************************************************

 

by: RDAdamsPosted on 2003-11-11 at 14:11:36ID: 9726219

Except that I don't want to delete cookies.

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

 

by: RDAdamsPosted on 2003-11-13 at 10:24:17ID: 9741486

When I run this I get a VBS compilation error in line 3.

Any other ideas folks???

 

by: RDAdamsPosted on 2003-11-13 at 13:46:30ID: 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

 

by: RDAdamsPosted on 2003-11-13 at 13:48:10ID: 9743075

Thanks for your ideas Petelong.  You certainly assisted in jogging my memory.

 

by: PeteLongPosted on 2003-11-13 at 14:15:58ID: 9743274

Glad I could be of some help

Pete

 

by: RDAdamsPosted on 2003-11-17 at 09:30:41ID: 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.

 

by: manch03Posted on 2004-02-16 at 07:42:27ID: 10372804

When you say you ran this file - from a command prompt?  Or do you run it?

 

by: Jimbob60Posted on 2004-04-29 at 06:35:46ID: 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

 

by: RDAdamsPosted on 2004-04-29 at 06:42:08ID: 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

 

by: manch03Posted on 2004-04-29 at 07:26:41ID: 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.

 

by: RDAdamsPosted on 2004-04-29 at 07:33:06ID: 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.

 

by: GudaPosted on 2004-06-03 at 19:35:10ID: 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

 

by: GudaPosted on 2004-06-03 at 19:36:38ID: 11229062

task manager... could i apply a script using task manager? or batch file?

 

by: CSCfermoyPosted on 2004-08-09 at 06:27:56ID: 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

 

by: jonnyddPosted on 2004-08-10 at 17:46:16ID: 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

 

by: RDAdamsPosted on 2004-08-11 at 07:47:41ID: 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.

 

by: jonnyddPosted on 2004-08-11 at 10:58:23ID: 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?

 

by: RDAdamsPosted on 2004-08-11 at 11:22:22ID: 11776626

Still not sure but have encountered other similar issues when trying to run programs automatically as a Domain Admin instead of local.

 

by: CSCfermoyPosted on 2004-08-19 at 09:21:02ID: 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

 

by: PeteLongPosted on 2004-08-19 at 09:22:33ID: 11843041

right click my computer >properties >advanced >enviroment variables

 

by: PeteLongPosted on 2004-08-19 at 09:24:46ID: 11843059

 

by: CSCfermoyPosted on 2004-08-19 at 09:32:12ID: 11843156

tried that couldn't see the variable for th system dive ?

 

by: CSCfermoyPosted on 2004-08-19 at 09:41:42ID: 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

 

by: RDAdamsPosted on 2004-08-19 at 10:03:01ID: 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

 

by: RDAdamsPosted on 2004-08-19 at 10:06:16ID: 11843618

Not sure if you need quotes arount the string but it might work.

 

by: CSCfermoyPosted on 2004-08-19 at 10:35:35ID: 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

 

by: RDAdamsPosted on 2004-08-19 at 10:37:55ID: 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.

 

by: CSCfermoyPosted on 2004-08-19 at 10:42:32ID: 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

 

by: RDAdamsPosted on 2004-08-19 at 10:50:04ID: 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.

 

by: BenEdwardsPosted on 2004-10-10 at 18:47:06ID: 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

 

by: RDAdamsPosted on 2004-10-11 at 05:35:40ID: 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

 

by: CSCfermoyPosted on 2004-10-11 at 06:07:21ID: 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
****************************************************************************************

 

by: RDAdamsPosted on 2004-10-11 at 06:10:54ID: 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.

 

by: BenEdwardsPosted on 2004-10-11 at 07:20:53ID: 12276681

Thanks RDAdams, that worked. I appreciate the help.

 

by: Jimbob60Posted on 2005-03-09 at 07:17:33ID: 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.

 

by: maheshkolvankarPosted on 2009-06-30 at 00:27:46ID: 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.



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



 

by: CitizenRonPosted on 2009-08-14 at 12:25:11ID: 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?

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...