简体   繁体   中英

How to write a batch file to download and install Firefox on Windows machine?

I need to write a startup batch script to download and install the latest version of Mozilla Firefox on a Windows Server 2016 machine. Your help is greatly appreciated.

Give a try for this batch script written by Sachadee .

::FIREFOX TOTAL SILENT FTP-INSTALL
::BY SachaDee
::08-2013
::www.batch.xoo.it

@echo off
setlocal ENABLEDELAYEDEXPANSION
:start
cls&color 18
md "%temp%\fire_install"
pushd "%temp%\fire_install"

@echo off
(echo anonymous
 echo.
 echo cd pub/mozilla.org/firefox/releases/latest/win32/fr
 echo mget *.exe
 echo bye)>firefox.ftp

ftp -s:firefox.ftp -i ftp.mozilla.org

if exist *.exe (echo firefox telecharger avec succes 
                for %%a in (*.exe) do (echo "%%a" | find /i "stub"
                                       set $en_cours=%%a
                                       if !errorlevel!==0 (del "!$en_cours!"
                                                           goto:install)))
:demande
set /p $rep=Le Download a ‚chou‚ recommencer ? [O/N] : 
if /i %$rep%==o goto:start
if /i %$rep%==n goto:end
cls&Echo La R‚ponse doit etre O ou N
goto:demande


:install
for %%a in (*.exe) do (CALL "%%a" -ms)
echo.&echo INSTALLATION TERMINEE
pause

:end
del /q "%temp%\fire_install"\*.*
endlocal
popd

Not the best code but it should work OK for what it sounds like you need. I just quickly made put it together. There might be a problem of where it asks you if you want to keep or discard the file due to the fact that it is an .exe file. I will still put in the code that would work without this problem. Change "dir=C:\\Users\\USERNAME\\Downloads" to the directory where your downloads go, IE C:\\Users\\Jim\\Downloads .

@echo off
title Download Firefox Newest Version
color 07

rem ---- Easily change site download and directory ----
set "dir=C:\Users\USERNAME\Downloads"
set "download=https://www.mozilla.org/en-US/firefox/new/?scene=2"

echo Opening Firefox Download... (%download%)

rem ---- Checks if file exists and if it does, start it ----
:openloop
pause
if exist %dir% (
    rem Firefox Exists
    cd %dir%
    echo Starting Firefox Installer.exe
    start Firefox Installer.exe
    exit 
) else (
    rem Firefox doesn't exist
    goto openloop
)

echo Whoops, something went wrong
pause >nul
exit

You can take a look at the Readme.txt of Mozilla Firefox for downloading the lastest version of firefox using a third party like wget or curl

Please use download.mozilla.org to retrieve the latest Firefox release.
For example, if you wish to download the US English installer for Windows (32bit)
the url is
   https://download.mozilla.org/?product=firefox-latest&os=win&lang=en-US

This could be pasted into the location bar of a browser, or used with curl or wget,  e.g. 
wget -O FirefoxSetup.exe "https://download.mozilla.org/?product=firefox-latest&os=win&lang=en-US"

For other operating systems replace 'os=win' with:
   Windows 64bit              os=win64
   OS X                       os=osx
   Linux x86_64               os=linux64
   Linux i686                 os=linux

For other languages replace 'lang=en-US' with:
   Acholi                     lang=ach
   Afrikaans                  lang=af
   Albanian                   lang=sq
   Arabic                     lang=ar
   Aragonese                  lang=an
   Armenian                   lang=hy-AM
   Assamese                   lang=as
   Asturian                   lang=ast
   Azerbaijani                lang=az
   Basque                     lang=eu
   Belarusian                 lang=be
   Bengali (Bangladesh)       lang=bn-BD
   Bengali (India)            lang=bn-IN
   Bosnian                    lang=bs
   Breton                     lang=br
   Bulgarian                  lang=bg
   Catalan                    lang=ca
   Chinese (Simplified)       lang=zh-CN
   Chinese (Traditional)      lang=zh-TW
   Croatian                   lang=hr
   Czech                      lang=cs
   Danish                     lang=da
   Dutch                      lang=nl
   English (British)          lang=en-GB
   English (South African)    lang=en-ZA
   Esperanto                  lang=eo
   Estonian                   lang=et
   Finnish                    lang=fi
   French                     lang=fr
   Frisian                    lang=fy-NL
   Fulah                      lang=ff
   Gaelic (Scotland)          lang=gd
   Galician                   lang=gl
   German                     lang=de
   Greek                      lang=el
   Gujarati (India)           lang=gu-IN
   Hebrew                     lang=he
   Hindi (India)              lang=hi-IN
   Hungarian                  lang=hu
   Icelandic                  lang=is
   Indonesian                 lang=id
   Irish                      lang=ga-IE
   Italian                    lang=it
   Kannada                    lang=kn
   Kazakh                     lang=kk
   Khmer                      lang=km
   Korean                     lang=ko
   Latvian                    lang=lv
   Ligurian                   lang=lij
   Lithuanian                 lang=lt
   Lower Sorbian              lang=dsb
   Macedonian                 lang=mk
   Maithili                   lang=mai
   Malay                      lang=ms
   Malayalam                  lang=ml
   Marathi                    lang=mr
   Norwegian (Bokmål)        lang=nb-NO
   Norwegian (Nynorsk)        lang=nn-NO
   Oriya                      lang=or
   Persian                    lang=fa
   Polish                     lang=pl
   Portuguese (Brazilian)     lang=pt-BR
   Portuguese (Portugal)      lang=pt-PT
   Punjabi (India)            lang=pa-IN
   Romanian                   lang=ro
   Romansh                    lang=rm
   Russian                    lang=ru
   Serbian                    lang=sr
   Sinhala                    lang=si
   Slovak                     lang=sk
   Slovenian                  lang=sl
   Songhai                    lang=son
   Spanish (Argentina)        lang=es-AR
   Spanish (Chile)            lang=es-CL
   Spanish (Mexico)           lang=es-MX
   Spanish (Spain)            lang=es-ES
   Swedish                    lang=sv-SE
   Tamil                      lang=ta
   Telugu                     lang=te
   Thai                       lang=th
   Turkish                    lang=tr
   Ukrainian                  lang=uk
   Upper Sorbian              lang=hsb
   Uzbek                      lang=uz
   Vietnamese                 lang=vi
   Welsh                      lang=cy
   Xhosa                      lang=xh

And here is another batch file using powershell to download the firefox setup with admin rights :

@echo off
Mode 80,5 & color 0A
Title Downloading Firefox Setup from web using powershell and batch by Hackoo 2018
:::::::::::::::::::::::::::::::::::::::::
:: Automatically check & get admin rights
:::::::::::::::::::::::::::::::::::::::::
REM  --> Check for permissions
Reg query "HKU\S-1-5-19\Environment" >nul 2>&1
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
Echo(
ECHO                      **************************************
ECHO                       Running Admin shell... Please wait...
ECHO                      **************************************

    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params = %*:"=""
   echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"

   "%temp%\getadmin.vbs"
   del "%temp%\getadmin.vbs"
   exit /B

:gotAdmin
::::::::::::::::::::::::::::
::START
::::::::::::::::::::::::::::
Mode 110,3 & color 0A
Set "URL=http://download.cdn.mozilla.net/pub/firefox/releases/57.0.4/win32/en-US/Firefox Setup 57.0.4.exe"
Set "FileLocation=%userprofile%\Desktop\Firefox Setup 57.0.4.exe"
echo(
echo         Please wait a while ... Downloading file to "%FileLocation%"
Call :BalloonTip 'information' 10 '"Downloading Firefox Setup.exe"' "'Please wait... Downloading Firefox Setup.exe....'" 'info' 4
Call :Download "%url%" "%FileLocation%"
If "%errorlevel%" EQU "1" ( 
    Color 0C
    echo There is an error occured ! & Timeout /T 4 /Nobreak>nul & exit
) else (
    If exist "%FileLocation%" Start "" "%FileLocation%"
)
Exit
::*********************************************************************************
:Download <url> <File>
Powershell.exe -command "(New-Object System.Net.WebClient).DownloadFile('%1','%2')"
exit /b
::*********************************************************************************
:BalloonTip $notifyicon $time $title $text $icon $Timeout
PowerShell  ^
  [reflection.assembly]::loadwithpartialname('System.Windows.Forms') ^| Out-Null; ^
[reflection.assembly]::loadwithpartialname('System.Drawing') ^| Out-Null; ^
$notify = new-object system.windows.forms.notifyicon; ^
  $notify.icon = [System.Drawing.SystemIcons]::%1; ^
  $notify.visible = $true; ^
  $notify.showballoontip(%2,%3,%4,%5); ^
  Start-Sleep -s %6; ^
  $notify.Dispose()
%End PowerShell%
exit /B
::********************************************************************************

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