-1

This is the code i am using to erase all the temporary files in the user machines, but i want to make it NOT erase the bookmarks of Mozilla Firefox and Google Chrome, i already did some research and found out the file that stores the bookmarks in firefox is "places.sqlite" how can i exclude it from the execution? And in the case of Chrome i am still looking...

Also... there is a lot of "@echo we are cleaning this" all around the code, to make it a litle user friendly and nice looking in general.

How i can make it so "file.exe" is not deleted on this command or is there a better way to do this?

What i exactly want to do is, a .bat file that makes the user enviroment i enter using mstsc.exethat is usualy a complete mess... something cleaner so that i can solve the users problem, this batch i made erase all the temporary files, browser profiles, cache of various programs, etc... of ALL USERS on a computer (and the computers i work with have so many users that windows makes temporary users) but i want to exclude some of the files from the process, so that the users dont complain about losing their Bookmarks, setting read only to these files is NOT an option and using third party programs, or code not suported inside a .bat file also is not an option.

I am a begginer in this and english is not my native language please bear with me...

@echo.
@echo *******************************************************************************
@echo * Limpando os temporarios de todos os usuarios em %COMPUTERNAME%
@echo *******************************************************************************

for /D %%G in ("%SystemDrive%\Users\*") do erase /F /S /Q "%%G\AppData\Local\Temp\*.*"
for /D %%G in ("%SystemDrive%\Users\*") do RD /S /Q "%%G\AppData\Local\Temp\"

@echo.
@echo *******************************************************************************
@echo * Limpando os temporarios do Windows em %COMPUTERNAME%
@echo *******************************************************************************

erase /F /S /Q "%SystemRoot%\TEMP\*.*"
for /D %%G in ("%SystemRoot%\TEMP\*") do RD /S /Q "%%G"

@echo.
@echo *******************************************************************************
@echo * Limpando cache do Internet Explorer em %COMPUTERNAME%
@echo *******************************************************************************

RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 260
for /D %%G in ("%SystemDrive%\Users\*") do erase /F /S /Q "%%G\AppData\Local\Microsoft\Windows\Tempor~1\*.*"
for /D %%G in ("%SystemDrive%\Users\*") do RD /S /Q "%%G\AppData\Local\Microsoft\Windows\Tempor~1\"

@echo.
@echo *******************************************************************************
@echo * Limpando cache do Google Chrome de todos os usuarios em %COMPUTERNAME%
@echo *******************************************************************************

taskkill /F /IM "chrome.exe">nul 2>&1
for /D %%G in ("%SystemDrive%\Users\*") do erase /F /S /Q "%%G\AppData\Local\Google\Chrome\User Data\*.*"
for /D %%G in ("%SystemDrive%\Users\*") do RD /S /Q "%%G\AppData\Local\Google\Chrome\User Data\"

@echo.
@echo *******************************************************************************
@echo * Limpando cache do Mozilla Firefox em %COMPUTERNAME%
@echo *******************************************************************************

taskkill /F /IM "firefox.exe">nul 2>&1
for /D %%G in ("%SystemDrive%\Users\*") do erase /F /S /Q "%%G\AppData\Local\Mozilla\Firefox\Profiles\*.*"
for /D %%G in ("%SystemDrive%\Users\*") do RD /S /Q "%%G\AppData\Local\Mozilla\Firefox\Profiles\"

@echo.
@echo *******************************************************************************
@echo * Limpando cache do Adobe Flash Player em %COMPUTERNAME%
@echo *******************************************************************************

for /D %%G in ("%SystemDrive%\Users\*") do erase /F /S /Q "%%G\AppData\Local\Macromedia\Flash Player\*.*"
for /D %%G in ("%SystemDrive%\Users\*") do erase /F /S /Q "%%G\AppData\Roaming\Macromedia\Flash Player\*.*"
for /D %%G in ("%SystemDrive%\Users\*") do RD /S /Q "%%G\AppData\Local\Macromedia\Flash Player\"
for /D %%G in ("%SystemDrive%\Users\*") do RD /S /Q "%%G\AppData\Roaming\Macromedia\Flash Player\"

@echo.
@echo *******************************************************************************
@echo * Limpando cache do Java em %COMPUTERNAME%
@echo *******************************************************************************

javaws -uninstall

@echo.
@echo *******************************************************************************
@echo * Limpando cache do Spooler de impressao em %COMPUTERNAME%
@echo *******************************************************************************

NET STOP SPOOLER
NET START SPOOLER

@echo.
@echo *******************************************************************************
@echo * Limpando cache DNS em %COMPUTERNAME%
@echo *******************************************************************************

ipconfig /flushdns
ipconfig /registerdns

@echo.
@echo *******************************************************************************
@echo * Realizando Update das configuracoes de %USERNAME% em %COMPUTERNAME%
@echo *******************************************************************************

GPUpdate /force
0

2 Answers 2

0

Just don't include these lines:

for /D %%G in ("%SystemDrive%\Users\*") do erase /F /S /Q "%%G\AppData\Local\Google\Chrome\User Data\*.*"

for /D %%G in ("%SystemDrive%\Users\*") do RD /S /Q "%%G\AppData\Local\Google\Chrome\User Data\"

for /D %%G in ("%SystemDrive%\Users\*") do erase /F /S /Q "%%G\AppData\Local\Mozilla\Firefox\Profiles\*.*"

for /D %%G in ("%SystemDrive%\Users\*") do RD /S /Q "%%G\AppData\Local\Mozilla\Firefox\Profiles\"

They are not temporary files, they're normal program files that should not be erased.

5
  • The author wants to get rid of all the other users files except the bookmarks. The obvious solution is to perform a branching routine on the name of the file.
    – Ramhound
    Feb 3, 2016 at 20:27
  • yes this will solve the problem, but... i need to clean these folders anyway because of file corruption caused by extreme bad use of the computers i handle in my work, i just want to keep the bookmarks so that the users dont complain about the vanishing of their links. Feb 3, 2016 at 21:14
  • and well... these may not be temporary files but it is where the user profiles of the respective browsers are stored, do you have a better solution to cleaning these browsers cache and history by using a batch command? Feb 3, 2016 at 21:58
  • 1
    Try this for Chrome (it deletes the cache folder and cookies and history files): superuser.com/questions/509063/… Feb 3, 2016 at 22:44
  • 1
    And here are the files and folders to be deleted for Firefox: forums.mozillazine.org/… Feb 3, 2016 at 22:44
0

I have Optimized my code and achieved what i was looking for by mannualy inputing the files and folders that seemed to be the right ones after some research, the problem of erasing the bookmarks is solved, and it still seems to be working as intended (a cure all .bat to clean stuff).

Here is the result

@echo off

cls Color 03

@echo. @echo ******************************************************************************* @echo * Limpando cache do Java em %COMPUTERNAME% @echo *******************************************************************************

javaws -uninstall

@echo. @echo ******************************************************************************* @echo * Limpando cache do Spooler de impressao em %COMPUTERNAME% @echo *******************************************************************************

NET STOP SPOOLER NET START SPOOLER

@echo. @echo ******************************************************************************* @echo * Limpando cache DNS em %COMPUTERNAME% @echo *******************************************************************************

ipconfig /flushdns ipconfig /registerdns

@echo. @echo ******************************************************************************* @echo * Realizando Update das configuracoes de %USERNAME% em %COMPUTERNAME% @echo *******************************************************************************

(echo n echo n) | GPUpdate /force /sync

@echo. @echo ******************************************************************************* @echo * Forçando Update do Windows em %COMPUTERNAME% @echo *******************************************************************************

wuauclt.exe /detectnow

@echo. @echo ******************************************************************************* @echo * Limpando os temporarios de todos os usuarios em %COMPUTERNAME% @echo *******************************************************************************

for /D %%G in ("%SystemDrive%\Users*") do erase /F /S /Q "%%G\AppData\Local\Temp*.*" for /D %%G in ("%SystemDrive%\Users*") do RD /S /Q "%%G\AppData\Local\Temp\"

@echo. @echo ******************************************************************************* @echo * Limpando os temporarios do Windows em %COMPUTERNAME% @echo *******************************************************************************

erase /F /S /Q "%SystemRoot%\TEMP*.*" for /D %%G in ("%SystemRoot%\TEMP*") do RD /S /Q "%%G"

@echo. @echo ******************************************************************************* @echo * Fechando IE e Chrome @echo *******************************************************************************

taskkill /F /IM "iexplore.exe">nul 2>&1 taskkill /F /IM "chrome.exe">nul 2>&1

@echo. @echo ******************************************************************************* @echo * Limpando cache do Internet Explorer em %COMPUTERNAME% @echo *******************************************************************************

RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 260 for /D %%G in ("%SystemDrive%\Users*") do erase /F /S /Q "%%G\AppData\Local\Microsoft\Windows\Tempor~1*." for /D %%G in ("%SystemDrive%\Users*") do erase /F /S /Q "%%G\AppData\Local\Microsoft\Windows\INetCache*." for /D %%G in ("%SystemDrive%\Users*") do erase /F /S /Q "%%G\AppData\Microsoft\Windows\Cookies*." for /D %%G in ("%SystemDrive%\Users*") do erase /F /S /Q "%%G\AppData\Microsoft\Windows\History*."

@echo. @echo ******************************************************************************* @echo * Limpando cache do Google Chrome de todos os usuarios em %COMPUTERNAME% @echo *******************************************************************************

for /D %%G in ("%SystemDrive%\Users*") do erase /F /S /Q "%%G\AppData\Local\Google\Chrome\User Data\Default\Cache*." for /D %%G in ("%SystemDrive%\Users*") do erase /F /S /Q "%%G\AppData\Local\Google\Chrome\User Data\Default\Local Storage*." for /D %%G in ("%SystemDrive%\Users*") do erase /F /S /Q "%%G\AppData\Local\Google\Chrome\User Data\Default\Media Cache*." for /D %%G in ("%SystemDrive%\Users*") do erase /F /S /Q "%%G\AppData\Local\Google\Chrome\User Data\Default\Pepper Data*." for /D %%G in ("%SystemDrive%\Users*") do erase /F /S /Q "%%G\AppData\Local\Google\Chrome\User Data\Default\Service Worker*." for /D %%G in ("%SystemDrive%\Users*") do erase /F /S /Q "%%G\AppData\Local\Google\Chrome\User Data\Default\Session Storage*." for /D %%G in ("%SystemDrive%\Users*") do erase /F /S /Q "%%G\AppData\Local\Google\Chrome\User Data\Default\Web Applications*." for /D %%G in ("%SystemDrive%\Users*") do erase /F /S /Q "%%G\AppData\Local\Google\Chrome\User Data\Default\IndexedDB*." for /D %%G in ("%SystemDrive%\Users*") do erase /F /Q "%%G\AppData\Local\Google\Chrome\User Data\Default\Web Data*" for /D %%G in ("%SystemDrive%\Users*") do erase /F /Q "%%G\AppData\Local\Google\Chrome\User Data\Default\Visited Links*" for /D %%G in ("%SystemDrive%\Users*") do erase /F /Q "%%G\AppData\Local\Google\Chrome\User Data\Default\Shortcuts*" for /D %%G in ("%SystemDrive%\Users*") do erase /F /Q "%%G\AppData\Local\Google\Chrome\User Data\Default\Top Sites*" for /D %%G in ("%SystemDrive%\Users*") do erase /F /Q "%%G\AppData\Local\Google\Chrome\User Data\Default\QuotaManager*" for /D %%G in ("%SystemDrive%\Users*") do erase /F /Q "%%G\AppData\Local\Google\Chrome\User Data\Default\Network*" for /D %%G in ("%SystemDrive%\Users*") do erase /F /Q "%%G\AppData\Local\Google\Chrome\User Data\Default\History*" for /D %%G in ("%SystemDrive%\Users*") do erase /F /Q "%%G\AppData\Local\Google\Chrome\User Data\Default\Cookies*" for /D %%G in ("%SystemDrive%\Users*") do erase /F /Q "%%G\AppData\Local\Google\Chrome\User Data\Default\Current*"

@echo. @echo ******************************************************************************* @echo * Limpando cache do Adobe Flash Player em %COMPUTERNAME% @echo *******************************************************************************

for /D %%G in ("%SystemDrive%\Users*") do erase /F /S /Q "%%G\AppData\Local\Macromedia\Flash Player*." for /D %%G in ("%SystemDrive%\Users*") do erase /F /S /Q "%%G\AppData\Roaming\Macromedia\Flash Player*." for /D %%G in ("%SystemDrive%\Users*") do RD /S /Q "%%G\AppData\Local\Macromedia\Flash Player\" for /D %%G in ("%SystemDrive%\Users*") do RD /S /Q "%%G\AppData\Roaming\Macromedia\Flash Player\"

<

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .