I found a script for removing firefox cookies and web cache to fix an issue we are having on a number of machines I support and I need to modify the script to affect all user folders instead of the current user. Is there a succinct command or change I could make to reach all user folders?
@echo off
set DataDir=C:\Users\%USERNAME%\AppData\Local\Mozilla\Firefox\Profiles
del /q /s /f "%DataDir%"
rd /s /q "%DataDir%"
for /d %%x in (C:\Users\%USERNAME%\AppData\Roaming\Mozilla\Firefox\Profiles\*) do del /q /s /f %%x\*sqlite
cls
IF %ERRORLEVEL%==0 (
@echo "Success Message"
timeout 10
) ELSE (
@echo "Error Message"
exit 1001
)
For perspective the environment is a couple of physically separate computer labs on a shared domain where users log in via their domain accounts. The original issue was that the image that was deployed to all the machines ended up having the login cookie and webcache data for one of our IT users in the default profile that all of the other local profiles build off of. This image was deployed during christmas break so countless users have already logged onto (and created profiles) on various machines.
Here you go buddy. Just loop through all directories of c:\Users
, and if exist (profiledir)
proceed with cleaning. Use conditional execution to handle success / fail (a little cleaner than if %ERRORLEVEL%==0
I think), and delayedexpansion
to evaluate variables within the loop. If there's a non-zero exit on either side of the first &&
, then the ||
code block fires. In other words, the failed message occurs and error count increments if either rd
or del *
fails.
@echo off
setlocal
set "errors=0"
for /f "delims=" %%I in ('dir /b /a:d c:\Users') do (
set "DataDir=c:\Users\%%I\AppData\Local\Mozilla\Firefox\Profiles"
setlocal enabledelayedexpansion
if exist "!DataDir!" (
rd /s /q "!DataDir!" && (
for /d %%x in ("!DataDir:\Local\=\Roaming\!\*") do (
del /q /s /f "%%~fx\*sqlite" && (
echo account %%~nI: Cleaning of Firefox profiles succeeded.
)
)
) || (
echo account %%~nI: Cleaning of Firefox profiles FAILED.
set /a errors += 1
)
)
endlocal
)
exit /b %errors%