Locating “Temporary Internet Files” from all profiles

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
anirajstha
Posts: 1
Joined: 04 Jul 2012 08:28

Locating “Temporary Internet Files” from all profiles

#1 Post by anirajstha » 04 Jul 2012 08:34

Basically I need to delete all the temporary files and I've got the following script for it. As all the locations are hard coded and not all people use the default location, I was wondering if anyone could help me with script which would be compatible with the current script that would detect all the "Temporary Internet Files" folder's locations from every profiles present and delete the unwanted. The solution would be a great help.

Code: Select all


cls
  SET SRC1=%SYSTEMDRIVE%\Documents and Settings
  SET SRC2=Local Settings\Temporary Internet Files
  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.


Thank you very much in advance.. :)

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Locating “Temporary Internet Files” from all profiles

#2 Post by Ed Dyreen » 06 Jul 2012 00:04

anirajstha wrote:detect all the "Temporary Internet Files" folder's locations from every profiles present and delete the unwanted.
Since noone has replied to your question/s within 24hrs, I'll give u some hints on how it could be done...

Don't get thrown off or ask questions on functions you do not have,
I could share them, but I'm afraid you just wouldn't understand, besides it is tested to work only on dutch releases of the winXP platform and my web-server's PHP interpreter is down which I am not happy about.

So first you need to get a list of all user profiles on the system, but in order to get that list we first have to get a list of the users themselves, this can be done with the 'net use /?' command.

Code: Select all

> "%%~§" ( for /f "skip=4 delims=" %%? in ( 'net.EXE user' ) do (echo.%%?) )
Now we can build a list of all user profiles on the system using the 'reg query /?' command.

Code: Select all

( %regKey.read_% $profile, "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DocFolderPaths", "!$name!" )
if defined $profile (

       ( %trimLeft_%  $profile, "\", 2 )
       ( %trimRight_% $profile, "\" )

) else set "$profile=!$name!"
Another and simpler way is to enumerate the profilesDir.

Next we load each users profile 'reg load /?' so we can read the regKey that holds the users temporary internet files path. Unload the user from registry and repeat this step for all users.

Code: Select all

( %reg.load_% $regHive, "!$profile!" )
( %regKey.read_% $TIF, "!$regHive!\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", "Cache", 1 )
( %reg.unLoad_% "!$regHive!", "!$profile!" )
You may have another problem; 'Temporary Internet Files' is misleading since the only browser guarantied to use this location is Internet Explorer. Thus a better name would be 'Internet Explorer's Temporary Files'.

I apologize for not providing you with a good to go solution, I just don't have the time.
These are just hints, I suggest you search the forums and http://www.dostips.com.
Please post your solutions and help any future visitors.

Good luck !

Post Reply