Wednesday, August 27, 2008

How to block Firefox from auto-updating

To block Firefox 2 from prompting users to update to Firefox 3, you need to add the following line to prefs.js in each profile:

user_pref("app.update.enabled", false);
The problem is that each profile is in a gibberish directory name. Mine happens to be 9eynycym.default:
C:\Documents and Settings\%username%\Application Data\Mozilla\Firefox\Profiles\9eynycym.default
So here's what I came up with for our domain login script:

:BlockFirefoxUpdate
for /F "tokens=1 delims= " %%a in ('dir "%appdata%\Mozilla\Firefox\Profiles" /b') do call :BlockFirefoxUpdateSub %%a
goto :BlockFirefoxUpdateEnd
:BlockFirefoxUpdateSub
type "%appdata%\Mozilla\Firefox\Profiles\%1\prefs.js" | find "app.update.enabled" | find "false"
if %errorlevel%==1 echo user_pref("app.update.enabled", false);>>"%appdata%\Mozilla\Firefox\Profiles\%1\prefs.js"
exit /b
:BlockFirefoxUpdateEnd

The only caveat to this is that if app.update.enabled is actually set to true instead of false, you'll have both in the file. But with a quick scan across the organization, I couldn't find anywhere where this was the case.

Explanation:

:BlockFirefoxUpdate
Label for this section of code, personal preference, keeps things neat.
for /F "tokens=1 delims= " %%a in ('dir "%appdata%\Mozilla\Firefox\Profiles" /b') do call :BlockFirefoxUpdateSub %%a
What this is doing is a dir /b (bare) in the Profiles\ directory. Then, for each line in this (such as 9eynycym.default), call :BlockFirefoxUpdateSub and pass it that line.
goto :BlockFirefoxUpdateEnd
Goes to the end so we don't run the code below an extra time.
:BlockFirefoxUpdateSub
Necessary to call from the for statement.
type "%appdata%\Mozilla\Firefox\Profiles\%1\prefs.js" | find "app.update.enabled" | find "false"
Look in our prefs.js, and see if it can find app.update.enabled and false on the same line.
if %errorlevel%==1 echo user_pref("app.update.enabled", false);>>"%appdata%\Mozilla\Firefox\Profiles\%1\prefs.js"
If it can't find it, put it there.
exit /b
Exit the Sub and go back to the next item in the for statement, if any.

:BlockFirefoxUpdateEnd
Label required for the goto above.