簡體   English   中英

通過命令提示符靜默更新 Firefox (Windows)

[英]Silently Updating Firefox via Command Prompt (Windows)

我有一個批處理文件,它會靜默安裝Firefox並且工作正常。 (我將-ms添加到執行安裝文件的行。)

現在我只想在同一個批處理文件中更新 Firefox,前提是它不是最新版本。 版本測試已經在批處理文件中並且工作正常。

現在我的問題是:如何靜默更新 Firefox?

我已經嘗試過此鏈接中的步驟,但它們不起作用,沒有錯誤,只是什么都不做。 也許還有另一種可能性?

編輯:

這是我的批處理文件的代碼。
該行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]).*$','$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.

如果你運行 Chocolately:

choco upgrade firefox -y

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM