Solved

Delete temp and IE cache files

Posted on 2013-01-09
8
839 Views
Last Modified: 2013-02-03
Hello fellow tech,

I have a scripts from a while ago the allow me to delete temp file and internet cache files.

Today the temp and ie one stop working and not sure where i when wrong.
It delete the temp and not the internet cache.

I know it got to be an easy fix just not seeing it.

Thanks all, CT

@echo off
taskkill /f /t /im iexplore.exe
cls
setlocal
cls
set UserRoot=C:\Documents and settings
set UserRoot2=c:\users
cls
REM *** Process all profile folders:
cls
for /d %%a in ("%UserRoot%\*.*") do call :process "%%a"
cls
REM *** Process the system temp folder:
cls
del /F /S /Q "c:\windows\temp\*.*" /s
cls
del /F /S /Q "c:\windows\system32\temp\*.*" /s
cls
del /F /S /Q "c:\windows\*.tmp" /s
cls
del /F /S /Q "c:\windows\*.temp" /s
cls
del /F /S /Q "c:\windows\system32\*.temp /s
cls
del /F /S /Q "c:\windows\system32\*.tmp" /s
cls
del /F /S /Q "c:\windows\prefetch\*.*" /s
cls
rd /s /q "c:\windows\temp"
cls
md "c:\windows\temp
cls
rd /s /q "c:\windows\system32\temp"
cls
goto :eof
:: *** subroutine 'process' starts here:
:process
set UserFolder=%~1
cls
echo Processing %UserFolder% ...
cls
REM *** %UserFolder% now contains the folder name currently being 

processed.
cls
REM *** Add your backup/deletion code between this line and the 

"goto :eof" at the end:
cls
del /F /S /Q "%UserFolder%\local settings\temp\*.*" /s
rd  /s /q "%UserFolder%\local settings\temp"
cls
md "%UserFolder%\local settings\temp"
attrib -h -s "%UserFolder%\local settings\temporary internet files"
cls
del /F /S /Q "%UserFolder%\local settings\temporary internet files

\*.*"
rd /s /q "%UserFolder%\local settings\temporary internet files"
cls
md "%UserFolder%\local settings\temporary internet files"
:eof

Open in new window

0
Comment
Question by:ComputerTechie
  • 5
  • 2
8 Comments
 
LVL 38

Expert Comment

by:BillDL
ID: 38762151
What text editor have you used to open and edit that batch file?  Windows Notepad?

Line 56 has a carriage return and line feed after   \temporary internet files   so that the remainder of the line is on line 58 of the code snippet. Perhaps it is the code snippet box here that has messed it up, but Notepad in XP has a nasty habit of messing up like this.  Maximize Notepad > Format menu > disable Word Wrap > make sure lines are continuous > Save.  Try the batch file again and see what happens.
0
 
LVL 23

Author Comment

by:ComputerTechie
ID: 38762953
I did check the line as and it did have a extra return there.
I now using notepad ++  One thing i notice this time is the call to :process is not working:

 
@echo on
color e0
echo                  Temp Cleaner - Verson A
echo .
echo .
echo .
echo .
echo .
taskkill /f /t /im iexplore.exe

setlocal

set UserRoot=C:\Documents and settings
set UserRoot2=c:\users

REM *** Process all profile folders:

for /d %%a in ("%UserRoot%\*.*") do call :process "%%a"

REM *** Process the system temp folder:

del /F /S /Q "c:\windows\temp\*.*" /s

del /F /S /Q "c:\windows\system32\temp\*.*" /s

del /F /S /Q "c:\windows\*.tmp" /s

del /F /S /Q "c:\windows\*.temp" /s

del /F /S /Q "c:\windows\system32\*.temp /s

del /F /S /Q "c:\windows\system32\*.tmp" /s

del /F /S /Q "c:\windows\prefetch\*.*" /s

rd /s /q "c:\windows\temp"

md "c:\windows\temp

rd /s /q "c:\windows\system32\temp"

goto :eof
:: *** subroutine 'process' starts here:
:process
set UserFolder=%~1

echo Processing %UserFolder% ...

REM *** %UserFolder% now contains the folder name currently being processed.

REM *** Add your backup/deletion code between this line and the "goto :eof" at the end:

del /F /S /Q "%UserFolder%\local settings\temp\*.*" /s
rd  /s /q "%UserFolder%\local settings\temp"

md "%UserFolder%\local settings\temp"
attrib -h -s "%UserFolder%\local settings\temporary internet files"

del /F /S /Q "%UserFolder%\local settings\temporary internet files\*.*"
rd /s /q "%UserFolder%\local settings\temporary internet files"

md "%UserFolder%\local settings\temporary internet files"
:eof

Open in new window

0
 
LVL 13

Expert Comment

by:Gabriel Clifton
ID: 38763809
I also noticed that even though you do use set UserRoot=c:\Documents and Settings and set UserRoot2=C:\Users, that is as far as it goes for windows 7. When this is ran even on Windows 7 it still looks for users in C:\documents and settings.

This can help you get started.

SET Version=Unknown

VER | FINDSTR /IL "5.0" > NUL
IF %ERRORLEVEL% EQU 0 SET Version=2000

VER | FINDSTR /IL "5.1." > NUL
IF %ERRORLEVEL% EQU 0 SET Version=XP

VER | FINDSTR /IL "5.2." > NUL
IF %ERRORLEVEL% EQU 0 SET Version=2003

VER | FINDSTR /IL "6.0." > NUL
IF %ERRORLEVEL% EQU 0 SET Version=Vista

VER | FINDSTR /IL "6.1." > NUL
IF %ERRORLEVEL% EQU 0 SET Version=7


:: Start code here...
IF DEFINED ProgramFiles(x86) ( Set Bit=X64
) ELSE (
Set Bit=X32 )

echo Windows %Version% %Bit%

if "%Version% %Bit%"=="XP X32" goto winxp32
if "%Version% %Bit%"=="XP X32 " goto winxp32
if "%Version% %Bit%"=="7 X32" goto win732
if "%Version% %Bit%"=="7 X32 " goto win732
if "%Version% %Bit%"=="7 X64" goto win764
if "%Version% %Bit%"=="7 X64 " goto win764
if "%Version%"=="Unknown" goto unknown

:winxp32
0
 
LVL 38

Expert Comment

by:BillDL
ID: 38765621
Hi ComputerTechie

I'm at work at the moment (non-IT environment) so I can't test anything, but there are two things I noticed that may or may not have a bearing on the functionality.

1. Avoid using double colons to remark out lines, and instead use REM.  You want to eliminate all characters that could be interpreted as being part of a command in certain circumstances, labels, redirection symbols, etc, etc.  Lines 42 to 44:

goto :eof
:: *** subroutine 'process' starts here:
:process

Make it this instead:

goto :eof
REM *** subroutine process starts here:
:process

2. The  goto EOF is assumed to be a "go to end and quit" instruction, and the actual label doesn't have to be given at the end of the batch file.  You can either change  :eof  to a label of another name and send your goto to that label, or else you can just leave it off the end of the batch file and use  goto :eof or even an exit /b command.  For testing purposes though, it is useful to end on a PAUSE.  Change the instances of  :eof  to  :end and then put a PAUSE command after the :end label so that the batch file stops there with a "press any key to end" and you can see what errors may have shown, otherwise it's just going to run and close.

3. For some versions of Internet Explorer there was a way of calling the "Internet Options" Control Panel applet from the command line so that it performs the same cleanup you would get by doing it manually.  I will have to check this out later when I get home.  It might save a lot of messing around, but it may just have been for IE6.

Have you ever used CCleaner?  http://www.piriform.com/ccleaner
0
Too many email signature updates to deal with?

Do you feel like you are taking up all of your time constantly visiting users’ desks to make changes to email signatures? Wish you could manage all signatures from one central location, easily design them and deploy them quickly to users? Well, there is an easy way!

 
LVL 38

Accepted Solution

by:
BillDL earned 500 total points
ID: 38767403
Just updating what I mentioned in the 3rd point in my comment.  The command line cleanup commands that I remembered still seem to be present in Internet Explorer on XP, but I haven't checked more recent versions.

You can call an internal function within a DLL file by having RunDLL32.exe call the named function within that DLL like this (excluding the full paths which are usually C:\Windows\System32 and aren't needed anyway):

RunDll32 filename.dll,FunctionName Parameter

To launch most Control Panel applets (*.cpl files) you usually need to have RunDLL32.exe call the Control_RunDLL function within shell32.dll and pass to it the name of the *.cpl file and values that control how you want it to open:

RunDll32 shell32.dll,Control_RunDLL filename.cpl,val1,val2

The command   control.exe  works the same like this:

control filename.cpl,val1,val2

To launch the Internet Options Control Panel applet inetcpl.cpl) this format of command works:

RunDLL32.exe inetcpl.cpl,FunctionName Value

The following values for the "ClearMyTracksByProcess" function should work in Internet Explorer versions up to IE8 and possibly more recent versions also:

RunDll32 InetCpl.cpl,ClearMyTracksByProcess 1       (Deletes History Only)
RunDll32 InetCpl.cpl,ClearMyTracksByProcess 2       (Deletes Cookies Only)
RunDll32 InetCpl.cpl,ClearMyTracksByProcess 8      (Deletes Temporary Internet Files Only)
RunDll32 InetCpl.cpl,ClearMyTracksByProcess 16    (Deletes Form Data Only)
RunDll32 InetCpl.cpl,ClearMyTracksByProcess 32    (Deletes Password History Only)
RunDll32 InetCpl.cpl,ClearMyTracksByProcess 255   (Deletes ALL History)

Other untested values I found listed are:
193 = clear add on history
2048 = clear IE Tracking
16384 = clear IE Downloaded Files

I can also see that there is a function named "ClearPhishingFilterData", but I am not sure if this can be called from the command line nor what values it might accept (if any) if it does work from the command line.

If you are interested it would be easy enough to test out and monitor what is deleted.

EDIT:
I have since discovered this:
http://www.winhelponline.com/blog/rundll32-command-clear-ie-cache-ineffective-windows-vista-higher/

"The rundll32 command-line involving inetcpl.cpl and the entrypoint ClearMyTracksByProcess which is widely in use since Internet Explorer 7, is ineffective in Windows Vista and above. This is because in Windows Vista and higher, Internet Explorer manages two different cache containers, one for the Protected Mode and another cache folder to store files when Internet Explorer is outside the Protected Mode."

Read the article for more detail
0
 
LVL 13

Expert Comment

by:Gabriel Clifton
ID: 38767537
BillDl, tested those on ie9 and 10 win7 x64, works like a champ. I cannot find anything on a script or command for clearphishingfilterdata either.
0
 
LVL 38

Expert Comment

by:BillDL
ID: 38767625
Thanks for checking that out PantherTech, I'm on XP and my Win7 laptop is in a closet behind loads of tools right now ;-)
0
 
LVL 38

Expert Comment

by:BillDL
ID: 38848442
Thank you ComputerTechie
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This is an article about Leadership and accepting and adapting to new challenges. It focuses mostly on upgrading to Windows 10.
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…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

758 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

18 Experts available now in Live!

Get 1:1 Help Now