Wednesday, June 02, 2010

Removing Firefox (BATCH)

For whatever reason, I had/have the task of removing Mozilla Firefox from our PCs in an automated way. I figured I could do it from a batch file, a .CMD file, but here's the proof:

@ECHO OFF
CLS
ECHO Checking for Firefox...
FOR /F "tokens=* skip=4 delims=" %%a in ('reg query "HKLM\Software\Mozilla\Mozilla Firefox" /v CurrentVersion') do SET DATA=%%a
IF "%DATA:~31,1%"=="." goto :longVersion
SET CVersion=%DATA:~26,5%
SET FVersion=%DATA:~26,20%
goto :versionCaptured
:longVersion
SET CVersion=%DATA:~26,7%
SET FVersion=%DATA:~26,20%
:versionCaptured

FOR /F "tokens=* skip=4" %%a in ('reg query "HKLM\Software\Mozilla\Mozilla Firefox\%FVersion%\Main" /v "Install Directory"') do SET DATA=%%a
SET IFolder=%DATA:~25%
ECHO *%CVersion%*
ECHO *%FVersion%*
ECHO *%IFolder%*
IF "%CVersion%"=="3.5.9" goto :DoNotRemove
goto :RemoveFirefox

:RemoveFirefox
echo The installed version is not approved for use in our environment.
TASKKILL /F /IM firefox.exe
CALL "%IFolder%\uninstall\helper.exe" /S
goto :eof

:DoNotRemove
echo This version is approved for use in our environment.
goto :eof

We like version 3.5.9, so we keep that version, but we need to revert or upgrade any other version. This is part of a bigger process, but...

No comments:

There is no individual ownership when you are part of a team, it's the sum of the parts that makes you the RESILIENT team you need to be.