如何通过脚本配置Firefox?


9

我想通过脚本(VBS或批处理)配置以下Firefox设置

  • 默认主页
  • 默认搜索引擎
  • 禁用自动更新

这可能吗?

Answers:


10

你可以这样做 创建或操作Mozilla首选项文件 使用您首选的脚本语言。

有关可通过这些文件设置的首选项列表,请参阅 Mozilla偏好 about:config中 文档,虽然与您的列表对应的文档似乎是: -

  • browser.startup.homepage (默认主页)
  • browser.search.defaultenginename (默认搜索引擎)
  • app.update.auto (启用/禁用自动更新)

但是,根据您的环境,您可能会发现通过自定义加载项推送设置会更好(请参阅中的XPI注释) Mozilla偏好简要指南 ),或通过GPO FirefoxADM 或类似的。


FirefoxADM是否允许您选择默认搜索引擎?
asp316

点击链接查找!
surfasb

我没有使用FADM,但是浏览源代码时,它并没有出现。但是,您可以修改它以执行此操作,并将更改提交回项目。
Kanji

2

您可以在用户配置文件文件夹中覆盖文件user.js中的私有浏览器选项。我经常使用它来覆盖一些选项,例如流水线。更新user.js后需要重新启动Firefox。如果文件user.js不存在,则必须创建一个。


0

从字面上复制/粘贴我正在寻找的答案的一部分 (赢得环境)

'C:\Users\User\AppData\Roaming\Mozilla\Firefox\Profiles\#####.default\prefs.js'

user_pref("browser.startup.homepage", "http://www.URL");

我尝试使用Get-Content / cat string.txt /“String”>>复制到远程计算机路径,最后插入垃圾的垃圾 prefs.js 文件由于字符串中的转义字符。


0
cd /D "%APPDATA%\Mozilla\Firefox\Profiles\*.default"

set ffile=%cd%

echo user_pref("browser.startup.homepage", "http://superuser.com");>>"%ffile%\prefs.js"
echo user_pref("browser.search.defaultenginename", "Google");>>"%ffile%\prefs.js"
echo user_pref("app.update.auto", false);>>"%ffile%\prefs.js"
set ffile=

cd %windir%

1
欢迎来到超级用户。如果您稍微解释一下代码,您的答案会更好。我为你修改了它的格式(我希望我没有破坏代码)。我有一个疑问:我猜你的代码会添加行而不是覆盖现有代码。我对吗?即使它只是特定选项的最后一次出现(因此您的更改有效),文件也会随着每次重新配置而不必要地增长,收集越来越多的这些选项的实例,除非Firefox本身用saner覆盖文件办法。您的解决方案针对此方案进行了测试
Kamil Maciorowski

0

这个帖子很老了,但我想分享我的解决方案。希望这有助于某人。我们有类似的问题,并希望将Windows商店的证书添加到Firefox中。所以我创建了一个脚本来执行此操作。无论如何,您可以根据需要进行更改:只需添加或删除:: create cfg_file_name.cfg [...]中的行并插入您需要的行,例如: echo pref("browser.startup.homepage", " http://superuser.com “^); 用于开始主页等。记得在最后一个之前设置^,否则它将无效!

从版本49开始,您可以这样做:

@echo off
setlocal enabledelayedexpansion
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: MAIN INFORMATION
:: Title: Change about:config entries in Mozilla Firefox
:: Author: I-GaLaXy-I
:: Version: 1.1
:: Last Modified: 10.01.2018
:: Last Modified by: I-GaLaXy-I
::------------------------------------------------------------------------------
:: This script will add two files, which will change about:config parameters of
:: Mozilla Firefox. You can change the name of these two files and remove or add
:: parameters according to your needs. Renaming the files could be essential, if
:: a user creates own files and you don't want to overwrite them.
:: 
:: If the two files already exist and the script is run, the complete content
:: of both files will be overwritten!
::
:: Note: You may have to run it with administrative privileges!
::
:: More information: https://developer.mozilla.org/en-US/Firefox/Enterprise_deployment
:: http://kb.mozillazine.org/Locking_preferences
::------------------------------------------------------------------------------
:: Subtitle: Import CAs from Windows certificate store
:: More information: https://serverfault.com/questions/722563/how-to-make-firefox-trust-system-ca-certificates
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: Set the name of the .cfg file
set cfg_file_name=add_win_certstore_cas

:: Set the name of the .js file
set js_file_name=add_win_certstore_cas

:: Registry keys to check for the installation path of Mozilla Firefox
set regkey1="HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\Windows\CurrentVersion\App Paths\firefox.exe" /v "Path"
set regkey2="HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\FIREFOX.EXE\shell\open\command" /ve

:: Get installation path of Mozilla Firefox (if not found exit script):
reg query %regkey1%
if %errorlevel%==0 (
    :: First key found, getting path
    for /f "tokens=2* delims=    " %%a in ('reg query %regkey1%') do set path_firefox=%%b
) else (
    :: If first key not found, try another one:
    reg query %regkey2%
    if !errorlevel!==0 (
        for /f "tokens=2* delims=    " %%a in ('reg query %regkey2%') do set path_firefox=%%b
        set path_firefox=!path_firefox:\firefox.exe=!
        for /f "useback tokens=*" %%a in ('!path_firefox!') do set path_firefox=%%~a
) else (
    :: No key found, exit script
    exit
))

:: Create cfg_file_name.cfg if it doesn't exist and input the following lines.
:: Caution! If cfg_file_name.cfg already exists, all lines will be overwritten!
:: Add more lines as needed with the following syntax: 
::echo pref("<name_of_config_entry>", <value>^);
(
    echo //Firefox Settings rolled out via KACE from Systec
    echo //Do not manually edit this file because it will be overwritten!
    echo //Import CAs that have been added to the Windows certificate store by an user or administrator.
    echo pref("security.enterprise_roots.enabled", true^);
) > "%path_firefox%\%cfg_file_name%.cfg"

:: Create js_file_name.js if it doesn't exist and input the following lines.
:: Caution! If js_file_name.js already exists, all lines will be overwritten!
(
    echo /* Firefox Settings rolled out via KACE from Systec
    echo Do not manually edit this file because it will be overwritten! */
    echo pref("general.config.obscure_value", 0^);
    echo pref("general.config.filename", "%cfg_file_name%.cfg"^);
) > "%path_firefox%\defaults\pref\%js_file_name%.js"

:: Files created, exit
exit
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.