通过命令提示符静默更新 Firefox (Windows)

Silently Updating Firefox via Command Prompt (Windows)

我有一个批处理文件,它可以静默安装 Firefox,而且效果很好。 (我在执行安装文件的那一行加上-ms。)

现在我只想在同一个批处理文件中更新 Firefox,前提是它不是最新版本。版本测试已经在批处理文件中并且工作正常。

现在我的问题是:我如何静默更新 Firefox?

我已经尝试了此 link 中的步骤,但它们不起作用,没有错误,只是什么都不做。还有其他可能吗?

编辑:

这是我的批处理文件的代码。
if %errorlevel%==1 %INSTALLDIR%\Mozilla Firefox\updater.exe -ms 行需要替换为 Firefox 的静默更新(希望可以正常工作)。

@echo off

IF %PROCESSOR_ARCHITECTURE%==x86 SET INSTALLDIR=%ProgramFiles%
IF %PROCESSOR_ARCHITECTURE%==AMD64 SET INSTALLDIR=%ProgramFiles(x86)%

IF NOT EXIST "%INSTALLDIR%\Mozilla Firefox\firefox.exe" goto install

REM Update Firefox if the Version is not 37.0
:update
CD %INSTALLDIR%\Mozilla Firefox\
firefox -v | more | find /i "37"
if %errorlevel%==0 goto end
if %errorlevel%==1 %INSTALLDIR%\Mozilla Firefox\updater.exe -ms
goto end

REM Install Firefox if it's not installed yet
:install
\***\***\Firefox-Setup-37.exe -ms

我建议为此任务使用以下注释批处理代码:

@echo off
set "FirefoxFolder="
set "FirefoxVersion=37"

rem Get path of installed Firefox directly from Windows registry.
for /F "skip=2 tokens=1,2*" %%I in ('%SystemRoot%\System32\reg.exe query "HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\firefox.exe" /v Path 2^>nul') do (
    if /I "%%I" == "Path" (
        set "FirefoxFolder=%%K"
        if defined FirefoxFolder goto CheckFirefox
    )
)

:InstallFirefox
echo Installing Firefox ...

:UpdateFireFox
\***\***\Firefox-Setup-%FirefoxVersion%.exe -ms
goto :EOF

:CheckFirefox
if not exist "%FirefoxFolder%\firefox.exe" goto InstallFirefox

rem Check if version of Mozilla Firefox starts with defined number.
rem The space at beginning makes sure to find the major version number.
"%FirefoxFolder%\firefox.exe" -v | %SystemRoot%\System32\more | %SystemRoot%\System32\find.exe " %FirefoxVersion%" >nul
if errorlevel 1 (
    echo Updating Firefox to version %FirefoxVersion% ...
    goto UpdateFireFox
)

echo Firefox with version %FirefoxVersion% is already installed.

Firefox 可执行文件的路径直接从 Windows 注册表中读取。这应该适用于任何 Windows,甚至 Windows XP。

我读到要更新 Firefox 只需执行安装程序。安装程序会自动检测已安装的 Firefox 版本并在不更改用户设置的情况下对其进行更新。

我非常喜欢 Mofi 的代码,因此我继续使用 curl 和 powershell 将其转换为完全无人值守的安装程序。谢谢莫菲! 运行 这段代码,无论是否安装了 firefox,您都将拥有最新的 firefox 版本!

@echo off
set "FirefoxFolder="
Title Firefox Updater
curl --silent -o "%TEMP%\firefoxdl.txt" "https://download.mozilla.org/?product=firefox-latest-ssl&os=win64&lang=en-US"
powershell -command "(Get-Content "%TEMP%\firefoxdl.txt") | ForEach-Object { $_ -replace '^.*releases.([0-9][0-9]).*$','' } | Set-Content "%TEMP%\firefoxdl.txt""
set /p FirefoxVersion=<"%TEMP%\firefoxdl.txt"
del "%TEMP%\firefoxdl.txt"
Echo The Latest Release of Firefox is version %FirefoxVersion%.

rem Get path of installed Firefox directly from Windows registry.
for /F "skip=2 tokens=1,2*" %%A in ('%SystemRoot%\System32\reg.exe query "HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\firefox.exe" /v Path 2^>nul') do (
    if /I "%%A" == "Path" (
        set "FirefoxFolder=%%C"
        if defined FirefoxFolder goto CheckFirefox
    )
)

:InstallFirefox

:UpdateFireFox
Echo Downloading Firefox Version %FirefoxVersion%...
curl --silent -L -o "%TEMP%\firefoxcurrent.exe" "https://download.mozilla.org/?product=firefox-latest-ssl&os=win64&lang=en-US"
Echo Installing Firefox Version %FirefoxVersion%, please wait...
tasklist /fi "imagename eq firefox.exe" |find ":" > nul
if errorlevel 1 taskkill /f /im "firefox.exe" >nul 2>&1
start "" /wait "%TEMP%\firefoxcurrent.exe" -ms
Echo Cleaning Up!
del "%TEMP%\firefoxcurrent.exe"
goto :EOF

:CheckFirefox
if not exist "%FirefoxFolder%\firefox.exe" goto InstallFirefox

rem Check if version of Mozilla Firefox starts with defined number.
rem The space at beginning makes sure to find the major version number.
"%FirefoxFolder%\firefox.exe" -v | %SystemRoot%\System32\more | %SystemRoot%\System32\find.exe " %FirefoxVersion%" >nul
if errorlevel 1 (
    echo Updating Firefox to version %FirefoxVersion% ...
    goto UpdateFireFox
)

echo However, Firefox version %FirefoxVersion% is already installed.

如果你是运行巧克力:

choco upgrade firefox -y