简体   繁体   中英

Silently Updating Firefox via Command Prompt (Windows)

I have a batch file which silently installs Firefox and this works fine. (I add -ms to the line where I execute the installation file.)

Now I want to update Firefox in the same batch file only if it's not the newest Version. The version test is already in the batch file and is working fine.

And now my Question is: How can I silently update Firefox?

I already tried the steps from this link but they are not working, no errors just doing nothing. Is there maybe another possibility?

Edit:

This is the code of my batch file.
The line if %errorlevel%==1 %INSTALLDIR%\Mozilla Firefox\updater.exe -ms needs to be replaced with the silent update for Firefox (which is hopefully working).

@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

I suggest for this task the following commented batch code:

@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.

The path to Firefox executable is read directly from Windows registry. This should work on any Windows, even on Windows XP.

I have read that for updating Firefox just the installer must be executed. The installer automatically detects an already installed version of Firefox and updates it without changing the user settings.

I liked Mofi's code so much I went ahead and transformed it into a fully unattended installer, using curl and powershell. Thank you Mofi! Run this code and you will have the latest firefox version whether firefox is already installed or not!

@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]).*$','$1' } | 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.

If you are running Chocolately:

choco upgrade firefox -y

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM