Skip to content

Latest commit

 

History

History
569 lines (529 loc) · 40.6 KB

README.md

File metadata and controls

569 lines (529 loc) · 40.6 KB

Update-MozillaFirefox.ps1

OS: Windows
Type: A Windows PowerShell script
Language: Windows PowerShell
Description:

Update-MozillaFirefox downloads a list of the most recent Firefox version numbers against which it compares the Firefox version numbers found on the system and displays, whether a Firefox update is needed or not. Update-MozillaFirefox detects the installed Firefoxes by querying the Windows registry for installed programs. The keys from HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\ and HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\ are read on 64-bit computers, and on the 32-bit computers only the latter path is accessed. At Step 7 Update-MozillaFirefox downloads and writes several Firefox-related files, namely "firefox_current_versions.json", "firefox_release_history.json", "firefox_major_versions.json", "firefox_languages.json" and "firefox_regions.json", which Update-MozillaFirefox uses as data sources. When run in a 'normal' PowerShell window, and all the detected Firefox versions seem to be up-to-date, Update-MozillaFirefox will just check that everything is OK and leave without further ceremony at Step 11.

If Update-MozillaFirefox is run without elevated rights (but with a working Internet connection) in a machine with an old Firefox version, it will be shown that a Firefox update is needed, but Update-MozillaFirefox will exit at Step 12 before downloading any files. To perform an update with Update-MozillaFirefox, PowerShell has to be run in an elevated window (run as an administrator). If Update-MozillaFirefox is run in an elevated PowerShell window and no Firefox is detected, the script offers the option to install Firefox in the "Admin Corner" (step 11), where, in contrary to the main autonomous nature of Update-MozillaFirefox, an end-user input is required for selecting the bit-version and the language. In the "Admin Corner", one instance of either 32-bit or 64-bit version in one of the available languages is installable with Update-MozillaFirefox – the language selection covers over 30 languages.

In the update procedure itself Update-MozillaFirefox downloads a full Firefox installer from Mozilla, which is equal to the type that is already installed on the system (same bit version and language). After writing the Install Configuration File (firefox_configuration.ini to $path at Step 14, where, for instance, the automatic Mozilla Maintenance service is disabled and the default shortcuts are enabled) and stopping several Firefox-related processes, Update-MozillaFirefox installs the downloaded Firefox on top of the existing Firefox installation, which triggers the in-built Firefox update procedure.

Homepage: https://github.com/auberginehill/update-mozilla-firefox
Short URL: http://tinyurl.com/gr75tjx
Version: 1.6
Sources: Emojis: Emoji Table
Tobias Weltner: PowerTips Monthly vol 8 January 2014 (or one of the archive.org versions)
ps1: Test Internet connection (or one of the archive.org versions)
Goyuix: Read Json Object in Powershell 2.0
lamaar75: Creating a Menu (or one of the archive.org versions)
alejandro5042: How to run exe with/without elevated privileges from PowerShell
JaredPar and Matthew Pirocchi: What's the best way to determine the location of the current PowerShell script?
Jeff: Powershell show elapsed time
Microsoft TechNet: Adding a Simple Menu to a Windows PowerShell Script
Downloads: For instance Update-MozillaFirefox.ps1. Or everything as a .zip-file.

Screenshot

            screenshot

Outputs

➡️
  • Displays Firefox related information in console. Tries to update an outdated Firefox to its latest version, if an old Firefox installation is found, and if Update-MozillaFirefox is run in an elevated Powershell window. In addition to that...

  • At Step 7 the baseline Firefox version numbers are written to a file (firefox_current_versions.json) and also four additional auxillary JSON files are created, namely:
    1. Firefox JSON Files (at Step 7):

      File Path
      firefox_current_versions.json %TEMP%\firefox_current_versions.json
      firefox_release_history.json %TEMP%\firefox_release_history.json
      firefox_major_versions.json %TEMP%\firefox_major_versions.json
      firefox_languages.json %TEMP%\firefox_languages.json
      firefox_regions.json %TEMP%\firefox_regions.json

      The %TEMP% location represents the current Windows temporary file folder. In PowerShell, for instance the command $env:temp displays the temp-folder path.

  • If the actual update procedure including the installation file downloading is initiated, a Firefox Install Configuration File (firefox_configuration.ini) is created with one active parameter (other parameters inside the file are commented out), and after Firefox has been updated, a web page displaying the latest version is opened in the default browser.
    1. Install Configuration File (at Step 14):

      File Path
      firefox_configuration.ini %TEMP%\firefox_configuration.ini

      The %TEMP% location represents the current Windows temporary file folder. In PowerShell, for instance the command $env:temp displays the temp-folder path.

  • To see the actual values that are being written to the Install Configuration File (firefox_configuration.ini), please see the Step 14 in the script itself, where the following value is written:
    1. Value Description
      MaintenanceService=false The MozillaMaintenance service is used for silent updates and may be used for other maintenance related tasks. It is an optional component. This option can be used in Firefox 16 or later to skip installing the service.

      For a comprehensive list of available settings and a more detailed description of the value above, please see the "Installer:Command Line Arguments" page.

  • To open these file locations in a Resource Manager Window, for instance a command

    Invoke-Item $env:temp

    may be used at the PowerShell prompt window [PS>].

Notes

⚠️
  • Requires either (a) PowerShell v3 or later or (b) .NET 3.5 or later for importing and converting JSON-files (at Step 8).

  • Requires a working Internet connection for downloading a list of the most recent Firefox version numbers and for downloading a complete Firefox installer from Mozilla (but the latter procedure is not initiated, if the system is deemed up-to-date).
  • For performing any actual updates with Update-MozillaFirefox, it's mandatory to run this script in an elevated PowerShell window (where PowerShell has been started with the 'run as an administrator' option). The elevated rights are needed for installing Firefox on top of the existing Firefox installation.
  • Update-MozillaFirefox is designed to update only one instance of Firefox. If more than one instances of Firefox are detected, the script will notify the user at Step 5, and furthermore, if old Firefox(es) are detected, the script will exit before downloading the installation file at Step 15.
  • Please note that the Firefox installation configuration file written at Step 14 disables the Mozilla Maintenance service so that the Mozilla Maintenance service will not be installed during the Firefox update. The values set with the Install Configuration File (firefox_configuration.ini) are altering the system files and seemingly are written somewhere deeper to the innards of Mozilla Firefox semi-permanently.
  • Please also notice that when run in an elevated PowerShell window and an old Firefox version is detected, Update-MozillaFirefox will automatically try to download files from the Internet without prompting the end-user beforehand or without asking any confirmations (at Step 16 and onwards) and at Step 17 closes a bunch of processes without any further notice.
  • Please note that the downloaded files are placed in a directory, which is specified with the $path variable (at line 42). The $env:temp variable points to the current temp folder. The default value of the $env:temp variable is C:\Users\<username>\AppData\Local\Temp (i.e. each user account has their own separate temp folder at path %USERPROFILE%\AppData\Local\Temp). To see the current temp path, for instance a command

    [System.IO.Path]::GetTempPath()

    may be used at the PowerShell prompt window [PS>]. To change the temp folder for instance to C:\Temp, please, for example, follow the instructions at Temporary Files Folder - Change Location in Windows, which in essence are something along the lines:
    1. Right click Computer icon and select Properties (or select Start → Control Panel → System. On Windows 10 this instance may also be found by right clicking Start and selecting Control Panel → System... or by pressing [Win-key] + X and selecting Control Panel → System). On the window with basic information about the computer...
    2. Click on Advanced system settings on the left panel and select Advanced tab on the "System Properties" pop-up window.
    3. Click on the button near the bottom labeled Environment Variables.
    4. In the topmost section, which lists the User variables, both TMP and TEMP may be seen. Each different login account is assigned its own temporary locations. These values can be changed by double clicking a value or by highlighting a value and selecting Edit. The specified path will be used by Windows and many other programs for temporary files. It's advisable to set the same value (a directory path) for both TMP and TEMP.
    5. Any running programs need to be restarted for the new values to take effect. In fact, probably Windows itself needs to be restarted for it to begin using the new values for its own temporary files.

Examples

📖 To open this code in Windows PowerShell, for instance:

  1. ./Update-MozillaFirefox
    Runs the script. Please notice to insert ./ or .\ before the script name.
  2. help ./Update-MozillaFirefox -Full
    Displays the help file.
  3. Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
    This command is altering the Windows PowerShell rights to enable script execution in the default (LocalMachine) scope, and defines the conditions under which Windows PowerShell loads configuration files and runs scripts in general. In Windows Vista and later versions of Windows, for running commands that change the execution policy of the LocalMachine scope, Windows PowerShell has to be run with elevated rights (Run as Administrator). The default policy of the default (LocalMachine) scope is "Restricted", and a command "Set-ExecutionPolicy Restricted" will "undo" the changes made with the original example above (had the policy not been changed before...). Execution policies for the local computer (LocalMachine) and for the current user (CurrentUser) are stored in the registry (at for instance the HKLM:\Software\Policies\Microsoft\Windows\PowerShell\ExecutionPolicy key), and remain effective until they are changed again. The execution policy for a particular session (Process) is stored only in memory, and is discarded when the session is closed.

    Parameters:

      Restricted Does not load configuration files or run scripts, but permits individual commands. Restricted is the default execution policy.
      AllSigned Scripts can run. Requires that all scripts and configuration files be signed by a trusted publisher, including the scripts that have been written on the local computer. Risks running signed, but malicious, scripts.
      RemoteSigned Requires a digital signature from a trusted publisher on scripts and configuration files that are downloaded from the Internet (including e-mail and instant messaging programs). Does not require digital signatures on scripts that have been written on the local computer. Permits running unsigned scripts that are downloaded from the Internet, if the scripts are unblocked by using the Unblock-File cmdlet. Risks running unsigned scripts from sources other than the Internet and signed, but malicious, scripts.
      Unrestricted Loads all configuration files and runs all scripts. Warns the user before running scripts and configuration files that are downloaded from the Internet. Not only risks, but actually permits, eventually, running any unsigned scripts from any source. Risks running malicious scripts.
      Bypass Nothing is blocked and there are no warnings or prompts. Not only risks, but actually permits running any unsigned scripts from any source. Risks running malicious scripts.
      Undefined Removes the currently assigned execution policy from the current scope. If the execution policy in all scopes is set to Undefined, the effective execution policy is Restricted, which is the default execution policy. This parameter will not alter or remove the ("master") execution policy that is set with a Group Policy setting.
      Notes:
      • Please note that the Group Policy setting "Turn on Script Execution" overrides the execution policies set in Windows PowerShell in all scopes. To find this ("master") setting, please, for example, open the Local Group Policy Editor (gpedit.msc) and navigate to Computer Configuration → Administrative Templates → Windows Components → Windows PowerShell.
      • The Local Group Policy Editor (gpedit.msc) is not available in any Home or Starter edition of Windows.
        1. Group Policy Setting "Turn on Script Execution" PowerShell Equivalent (concerning all scopes)
          Not configured No effect, the default value of this setting
          Disabled Restricted
          Enabled – Allow only signed scripts AllSigned
          Enabled – Allow local scripts and remote signed scripts RemoteSigned
          Enabled – Allow all scripts Unrestricted

    For more information, please type "Get-ExecutionPolicy -List", "help Set-ExecutionPolicy -Full", "help about_Execution_Policies" or visit Set-ExecutionPolicy or about_Execution_Policies.

  4. New-Item -ItemType File -Path C:\Temp\Update-MozillaFirefox.ps1
    Creates an empty ps1-file to the C:\Temp directory. The New-Item cmdlet has an inherent -NoClobber mode built into it, so that the procedure will halt, if overwriting (replacing the contents) of an existing file is about to happen. Overwriting a file with the New-Item cmdlet requires using the Force. If the path name and/or the filename includes space characters, please enclose the whole -Path parameter value in quotation marks (single or double):

      New-Item -ItemType File -Path "C:\Folder Name\Update-MozillaFirefox.ps1"

    For more information, please type "help New-Item -Full".

Contributing

contributing Bugs: Bugs can be reported by creating a new issue.
Feature Requests: Feature request can be submitted by creating a new issue.
Editing Source Files: New features, fixes and other potential changes can be discussed in further detail by opening a pull request.

www

🌐 Script Homepage
Tobias Weltner: PowerTips Monthly vol 8 January 2014 (or one of the archive.org versions)
ps1: Test Internet connection (or one of the archive.org versions)
Goyuix: Read Json Object in Powershell 2.0
lamaar75: Creating a Menu (or one of the archive.org versions)
alejandro5042: How to run exe with/without elevated privileges from PowerShell
JaredPar and Matthew Pirocchi: What's the best way to determine the location of the current PowerShell script?
Jeff: Powershell show elapsed time
Microsoft TechNet: Adding a Simple Menu to a Windows PowerShell Script
Microsoft TechNet: Working with Hash Tables
Determine installed PowerShell version
ConvertFrom-Json
ConvertFrom-StringData
PowerTip: Convert JSON File to PowerShell Object
PowerShell v2 Converts Dictionary to Array when returned from a function
Working with JSON and PowerShell
Perfect Progress Bars for PowerShell
MozillaZine: Software Update
Mozilla Wiki: Installer:Command Line Arguments
Mozilla Wiki: Software Update:Checking For Updates
Mozilla Release Engineering
MozillaZine: App.update.url
ASCII Art: http://www.figlet.org/ and ASCII Art Text Generator

Related scripts

www Disable-Defrag
Emoji Table
Firefox Customization Files
Get-AsciiTable
Get-BatteryInfo
Get-ComputerInfo
Get-CultureTables
Get-DirectorySize
Get-HashValue
Get-InstalledPrograms
Get-InstalledWindowsUpdates
Get-PowerShellAliasesTable
Get-PowerShellSpecialFolders
Get-RAMInfo
Get-TimeDifference
Get-TimeZoneTable
Get-UnusedDriveLetters
Get-Windows10LockScreenWallpapers
Java-Update
Remove-DuplicateFiles
Remove-EmptyFolders
Remove-EmptyFoldersLite
Rename-Files
Rock-Paper-Scissors
Toss-a-Coin
Unzip-Silently
Update-AdobeFlashPlayer