:: Mozilla extension installation demo script for Firefox and Thunderbird versions :: based on Gecko 1.9+ from which the -install-global-extension command line option :: has been removed. This script must be run from a Windows account with local :: administrative rights. The extensions it installs can be run immediately by :: limited users. :: :: Stephen Thomas 31-Jan-2010 :: :: This is free software. Do whatever you want with it except hold me accountable :: for the grief it will undoubtedly cause you. If you improve it, I'd like to hear :: from you. set mozextn=call :mozextn set return=goto :eof set rmdir=rmdir /s /q set xpidir=P:\Installers\Firefox Extensions set zip="%ProgramFiles%\7-Zip\7z.exe" :: Install an XPI package for all Thunderbird users %mozextn% Thunderbird english__australian__dictionary-2.1.1a-fx+tb+sm :: Install some XPI packages for all Firefox users %mozextn% Firefox adblock_plus-1.1.3 %mozextn% Firefox english__australian__dictionary-2.1.1a-fx+tb+sm %mozextn% Firefox ie_view-1.4.5.1-fx+mz-win %mozextn% Firefox user_agent_switcher-0.7.2a-fx+sm :: Demonstrate use of errorlevel to check safety of post-installation tweaks %mozextn% Firefox zotero-2.0rc2 if errorlevel 1 %return% set prefs="%extndir%\defaults\preferences\zotero.js" >>%prefs% echo. >>%prefs% echo // Site-local defaults >>%prefs% echo pref("extensions.zotero.dataDir", "N:\Zotero"); >>%prefs% echo pref("extensions.zotero.lastDataDir", "N:\Zotero"); >>%prefs% echo pref("extensions.zotero.useDataDir", true); %return% :: Install a Mozilla extension XPI package into a system-wide folder, and add :: the registry key required to tell the Mozilla app it's there. :: :: Uses the same root folder for all packages regardless of whether they are :: intended for Firefox or Thunderbird; this allows both apps to share disk space :: for any extensions they have in common. :: :: If there's already a folder in "%ProgramFiles%\Mozilla %appname%\extensions" :: named for the ID of the extension being installed, or if the registry key :: already exists and points to a different folder from the new one, the old :: folders are deleted before the registry key is updated. :: :: Parameters: :: :: %1: app name (Firefox or Thunderbird) :: %2: XPI package name, without trailing .xpi; also used to name the :: installation folder. :: :: Returns errorlevel 0 if installation worked, 1 if not. :: :: Uses a totally unsound hack to extract the package ID from its install.rdf :: file; will break horribly if the first XML tag encountered does not :: belong to the package ID, or if package-id is not all on :: one line. If you'd rather use a proper XML parser instead, be my guest. If :: it's really easy to do, let me know. :mozextn set extnroot=%ProgramFiles%\Common Files\Mozilla Shared\Extensions if not exist "%extnroot%" mkdir "%extnroot%" if errorlevel 1 %return% set extndir=%extnroot%\%2 if exist "%extndir%" %rmdir% "%extndir%" %zip% x -yo"%extndir%" "%xpidir%\%2.xpi" if errorlevel 1 %return% for /f "skip=2 tokens=*" %%L in ('find "" "%extndir%\install.rdf"') do @( set line="%%L" goto :mozextn1 ) :mozextn1 set id=%line:~8,-9% if "%id%"=="" ( %rmdir% "%extndir%" verify error 2>nul %return% ) set olddir=%ProgramFiles%\Mozilla %1\extensions\%id% if exist "%olddir%" %rmdir% "%olddir%" set key=HKLM\Software\Mozilla\%1\Extensions for /f "skip=4 tokens=2*" %%A in ('reg query "%key%" /v "%id%"') do set olddir=%%B if not "%olddir%"=="%extndir%" if exist "%olddir%" %rmdir% "%olddir%" reg add "%key%" /v "%id%" /d "%extndir%" /f %return%