Skip to content

Retrieves the latest Java version numbers from the Interwebs, and looks for the installed Java versions on the system. If any outdated Java versions are found, tries to update the Java (a Windows PowerShell script). ** Partially obsolete **

License

Notifications You must be signed in to change notification settings

auberginehill/java-update

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Java-Update.ps1

OS: Windows
Type: A Windows PowerShell script
Language: Windows PowerShell
Status: Partially obsolete, please see #1 for further details. Java-Update.ps1 doesn't seem to work with JRE Family Version 9 or later versions of Java. JRE Family Version 8 is deemed to be "the latest" by this script, which only seems to be factually true concerning the 32-bit Java versions.
Description:

Java-Update downloads a list of the most recent Java version numbers against which it compares the Java version numbers found on the system and displays, whether a Java update is needed or not. The actual update process naturally needs elevated rights, and if a working Internet connection is not found, Java-Update will exit at Step 8. Java-Update detects the installed Javas 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 32-bit computers only the latter path is accessed.

Java-Update tries to write several Java-related configuration files at an early stage, the "deployment.properties" -file in Step 4 and an Install Configuration File in Step 5 (java_config.txt). In Step 6, if enough rights are granted (run as an administrator) Java-Update tries to remove the excessive duplicate Java versions, so that only those Java versions, which are deemed to be the latest, would remain. Usually only one instance of Java will remain, but if both the 32-bit and 64-bit Javas have the same latest version number, both of the Java versions (32-bit and 64-bit) will be preserved. At this stage the Java Auto Updater will also be uninstalled. In Step 6 the msiexec.exe is called to uninstall old Javas, so the process runs at a normal pace.

If Java-Update is run without elevated rights (but with a working Internet connection) in a machine with old Java versions, it will be shown that a Java update is needed, but Java-Update will exit at Step 13 before actually downloading any files. To perform an update with Java-Update, PowerShell has to be run in an elevated window (run as an administrator).

If Java-Update is run in an elevated PowerShell window and no Java is detected, the script offers the option to install Java in the "Admin Corner", where, in contrary to the main autonomous nature of Java-Update, an end-user input is required.

If Java-Update is run with elevated rights (with a working Internet connection) in a machine with old Java versions, Java-Update tries first to remove the excessive duplicate Java versions (at Step 6), and in the update procedure (if the most recent non-beta Java version is not detected and Java-Update is run with administrative rights) Java-Update downloads the Java uninstaller from Oracle/Sun (a file which is not used with this script) and a full Java offline installer from Sun (the 64-bit Java for a 64-bit machine and the 32-bit Java for a 32-bit machine). After stopping several Java-related processes Java-Update uninstalls the outdated Java versions in two phases (Java Auto Updater first and then the other Javas as listed by Get-WmiObject -Class Win32_InstalledWin32Program command) with the msiexec.exe /uninstall command and installs the downloaded Java version.

Homepage: https://github.com/auberginehill/java-update
Short URL: http://tinyurl.com/hh7krx3
Version: 1.4
Sources: Emojis: Emoji Table
ps1: Test Internet connection (or one of the archive.org versions)
Tobias Weltner: PowerTips Monthly vol 8 January 2014 (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?
Microsoft TechNet: Adding a Simple Menu to a Windows PowerShell Script
lamaar75: Creating a Menu (or one of the archive.org versions)
Jeff: Powershell show elapsed time
Downloads: For instance Java-Update.ps1. Or everything as a .zip-file.

Screenshot

            screenshot

Outputs

➡️
  • Displays Java related information in console. Tries to remove excessive (duplicate) Java versions and update the one remaining instance of Java to the latest non-beta version (the 64-bit Java for a 64-bit machine and the 32-bit Java for a 32-bit machine), if old Java(s) is/are found, if Java-Update is run in an elevated Powershell window and if a working Internet connection is detected. In addition to that...

  • The Java Deployment Configuration File (deployment.properties) is altered with new parameters, if it is found in one of its default Windows locations, and the following backups are made.
    1. Java Deployment Configuration File in Step 4 (deployment.properties):

      Path Alternative File
      Windows path 1: %USER_HOME_DIRECTORY%\AppData\LocalLow\Sun\Java\Deployment\deployment.properties
      Windows path 2: %USER_HOME_DIRECTORY%\AppData\Roaming\Sun\Java\Deployment\deployment.properties

      "Original" file, which is created when the script is run for the first time:

      Path Alternative File
      Windows path 1: %USER_HOME_DIRECTORY%\AppData\LocalLow\Sun\Java\Deployment\deployment.properties_original
      Windows path 2: %USER_HOME_DIRECTORY%\AppData\Roaming\Sun\Java\Deployment\deployment.properties_original

      "Backup" file, which is created when the script is run for the second time and which gets overwritten in each successive time the script is run:

      Path Alternative File
      Windows path 1: %USER_HOME_DIRECTORY%\AppData\LocalLow\Sun\Java\Deployment\deployment.properties.old
      Windows path 2: %USER_HOME_DIRECTORY%\AppData\Roaming\Sun\Java\Deployment\deployment.properties.old

      An auxiliary "New" file, which contains the newest settings:

      Path Alternative File
      Windows path 1: %USER_HOME_DIRECTORY%\AppData\LocalLow\Sun\Java\Deployment\deployment.properties.new
      Windows path 2: %USER_HOME_DIRECTORY%\AppData\Roaming\Sun\Java\Deployment\deployment.properties.new

      The %USER_HOME_DIRECTORY% location represents the Home directory of an user, such as C:\Users\<username> and may be displayed in PowerShell with the [Environment]::GetFolderPath("User") command.

      The "Store user settings in the roaming profile" Java setting in the Java Control Panel (Advanced Tab) determines, whether the Windows path 1 or 2 is used. The default option is Windows path 1 (i.e. "Store user settings in the roaming profile" = false) i.e. %USER_HOME_DIRECTORY%\AppData\LocalLow\Sun\Java\Deployment\ is used by default.

  • To see the actual values that are being written, please see the Step 4 in the script itself, where the following values are added or forced (overwritten) upon the original settings:
    1. Value Description
      deployment.webjava.enabled=false Security Tab: Enable Java content in the browser
      Set to true to run applets or Java Web Start (JWS) applications.
      Set to false to block applets and JWS applications from running.
      install.disable.sponsor.offers=true Advanced Tab: Suppress sponsor offers when installing or updating Java

      For a comprehensive list of available settings in the deployment.properties file, please see the "Deployment Configuration File and Properties" page.

  • An Install Configuration File is created in Step 5.
    1. Install Configuration File in Step 5 (java_config.txt):

      OS File
      Windows: %TEMP%\java_config.txt

      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, please see the Step 5 in the script itself, where the following values are written:
    1. Value Description
      INSTALL_SILENT=1 Silent (non-interactive) installation
      AUTO_UPDATE=0 Disables the auto update feature
      WEB_JAVA=0 Disables Java in the browser.
      Configures the installation so that downloaded Java applications are not allowed to run in a web browser or by Java Web Start.
      WEB_JAVA_SECURITY_LEVEL=VH Sets the security level to very high
      WEB_ANALYTICS=0 Disallow the installer to send installation-related statistics to an Oracle server.
      EULA=0 If a Java applet or Java Web Start application is launched, do not prompt the user to accept the end-user license agreement.
      REBOOT=0 The installer will never prompt for restarting the computer after installing the JRE.
      REBOOT=Suppress
      REBOOT=ReallySuppress
      NOSTARTMENU=1 Specify that the installer installs the JRE without setting up Java start-up items.
      SPONSORS=0 Install Java without being presented with any third party sponsor offers.
      REMOVEOUTOFDATEJRES=1 Enables uninstallation of existing out of date JREs during JRE install. Using REMOVEOUTOFDATEJRES=1 removes all out-of-date Java versions from the system.

      For a comprehensive list of available settings in a Configuration File, please see the "Installing With a Configuration File" page.

  • After the installation the downloaded files (uninstaller and the install file) are not purged from the $path directory.
  • Additionally two auxiliary csv-files are created at $path and during the actual update procedure a log-file is also created to the same location.
    1. File Description
      %TEMP%\java_update_chart.csv Gathered from an online XML-file.
      %TEMP%\java_baseline.csv Contains the most recent Java version numbers.
      %TEMP%\java_install.log A log-file about the installation procedure.

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

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

    Invoke-Item ([string][Environment]::GetFolderPath("LocalApplicationData") + 'Low\Sun\Java\Deployment')

    or

    Invoke-Item ([string][Environment]::GetFolderPath("ApplicationData") + '\Sun\Java\Deployment')

    or

    Invoke-Item ("$env:temp")

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

Notes

⚠️
  • Requires a working Internet connection for downloading a list of the most recent Java version numbers.

  • Also requires a working Internet connection for downloading a Java uninstaller and a complete Java installer from Oracle/Sun (but this procedure is not initiated, if the system is deemed up-to-date). The download location URLs of the full installation files seem not to follow any pre-determined format anymore. The download locations of full installation files for both 32-bit and 64-bit Java versions are determined at Step 10 and Step 11.
  • For performing any actual updates with Java-Update, 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 uninstalling Java(s) and installing Java.
  • Please also notice that during the actual update phase Java-Update closes a bunch of processes without any further notice in Step 18 and may do so also in Step 6. Please also note that Java-Update alters the system files at least in Steps 4, 5, 19 and 24, so that for instance, all successive Java installations (even the ones not initiated by this Java-Update script) will be done "silently" i.e. without any interactive pages or prompts.
  • Please note that when run in an elevated PowerShell window and old Java(s) is/are detected, Java-Update will automatically try to uninstall them and download files from the Internet without prompting the end-user beforehand or without asking any confirmations (in Step 6 and from Step 16 onwards).
  • The notoriously slow and possibly harmful Get-WmiObject -Class Win32_Product command is deliberately not used for listing the installed Javas or for performing uninstallations despite the powerful Uninstall-method associated with this command, since the Win32_Product Class has some unpleasant behaviors – namely it uses a provider DLL that validates the consistency of every installed MSI package on the computer (msiprov.dll with the mandatorily initiated resiliency check, in which the installations are verified and possibly also repaired or repair-installed), which is the main reason behind the slow performance of this command. All in all Win32_product Class is not query optimized and in Java-Update a combination of various registry queries, msiexec.exe and Get-WmiObject -Class Win32_InstalledWin32Program is used instead.
  • Please note that the downloaded files are placed in a directory, which is specified with the $path variable (at line 15). 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. ./Java-Update
    Runs the script. Please notice to insert ./ or .\ before the script name.
  2. help ./Java-Update -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\Java-Update.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\Java-Update.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
ps1: Test Internet connection (or one of the archive.org versions)
Tobias Weltner: PowerTips Monthly vol 8 January 2014 (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?
lamaar75: Creating a Menu (or one of the archive.org versions)
Perfect Progress Bars for PowerShell
Adding a Simple Menu to a Windows PowerShell Script
Powershellv2 - remove last x characters from a string
ASCII Art: http://www.figlet.org/ and ASCII Art Text Generator

Related scripts

www Disable-Defrag
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
Emoji Table
Remove-DuplicateFiles
Remove-EmptyFolders
Remove-EmptyFoldersLite
Rename-Files
Rock-Paper-Scissors
Toss-a-Coin
Unzip-Silently
Update-AdobeFlashPlayer
Update-MozillaFirefox

About

Retrieves the latest Java version numbers from the Interwebs, and looks for the installed Java versions on the system. If any outdated Java versions are found, tries to update the Java (a Windows PowerShell script). ** Partially obsolete **

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published