Tuesday, April 21, 2015

Deploy Java 1.8 with MSI Enterprise Installers and PowerShell

*Edited 7/22/2015 - I neglected x86 OS's when I added the INSTALLDIR=""${Env:ProgramFiles(x86)}\Java\Jre8"" to the installation command, I've updated the script to check the OS version and install into the appropriate ProgramFiles.

*Edited 6/22/2015 - Our installs of Eclipse would error after Java updates because the eclipse.ini file tells the program where JRE is located. I found that Java installer is not installing Patch-in-Place like what use to be the default. I tried STATIC=0 in the install script and that didn't work either. So I added INSTALLDIR=""${Env:ProgramFiles(x86)}\Java\Jre8"" for x86 and INSTALLDIR=""$Env:ProgramFiles\Java\Jre8"" for x64, to the install command line to specifically tell Java which folder to install to.

*Edited 4/24/2015 - I found at least one case where an uninstall of Java will cause the computer to reboot. Therefore I have added a /norestart to the uninstall arguments, which is probably a good idea to always include.

*Note: As of version 8u40 there still appears to be a bug with the MSI installers which causes the install to fail if parameters are used when the system account installs the application. I have modified my installation to account for this.

With the introduction of Java 8u20, Oracle introduced their supported enterprise MSI installers.
Unfortunately as I noted above, if you use SCCM to deploy the MSI and use parameters in the install command line, the installation will fail. It may be possible to still extract the MSI's from the Java offline installer and deploy that instead of downloading the "Enterprise Installers". I didn't have success with that method any longer, but I haven't tried it since realizing that the MSI does not accept parameters.

First you will need access to MOS (My Oracle Support). My organization has Premier support, so I had to sign up and then add our Support Identifier and Organization Name and request access. This then emailed our "Customer User Administrator", a programmer on staff here who granted me download access.
Now I am free to download the msi enterprise installers as needed. Searching through the support site for "java enterprise msi", I was able to find the download links on a page called "All Java SE Downloads on MOS"

I chose the Oracle JRE 8 Update 40 MSI Enterprise Installer, you will be taken to a download page where you can choose the 32 or 64 bit versions. In this example, I am installing the 32bit version. Once downloaded you can extract the "jre-8u40-windows-i586.msi" from the zip file. There are just minor changes to the logic if you are going to do the 64 bit version.

With Java its better to make sure Internet Explorer is closed when uninstalling older versions. So I created a PowerShell script to check if IE is open, if it is open, it exits with a 1618 error code, which ConfigMgr interprets as a "fast retry". If IE is not open, it searches for and uninstalls older versions of Java except for ones with "(64-bit)" and "Development Kit" in their titles and then installs the new Java.

# Check if IE is open, some versions of Java cannot be removed if IE is open
# if IE is open, return a Fast Retry to SCCM and stop execution of script
if ( get-process iexplore -ErrorAction SilentlyContinue )
            Exit 1618

# Search and attempt removal of old Java's
$javaInstalls = get-wmiobject -namespace root\cimv2\sms -query "select * from SMS_InstalledSoftware where ProductName like 'Java%'"
foreach ($javaInstall in $javaInstalls)
if (($javaInstall.Productname -notmatch "(64-bit)") -and ($javaInstall.Productname -notmatch "Development Kit")) {
$software = $javainstall.softwarecode
$arguments = "/x $software /qn /norestart"
start-process msiexec.exe -ArgumentList $arguments -wait

if ((Get-WmiObject -Class Win32_OperatingSystem).OSArchitecture -eq '64-bit') {
    $InstallPath = ${Env:ProgramFiles(x86)} } 
    else {
    $InstallPath = $ENV:ProgramFiles

Start-Process jre-8u40-windows-i586.msi -ArgumentList "/qn INSTALLDIR=""$InstallPath\Java\JRE8"" /norestart" -Wait

# Remove Start Menu Items aka Parameter NOSTARTMENU="Enable"
if (Test-Path "$Env:ProgramData\Microsoft\Windows\Start Menu\Programs\Java")
    Remove-Item -Path "$Env:ProgramData\Microsoft\Windows\Start Menu\Programs\Java" -Force -Recurse
I call this PowerShell script "install_jre_x86.ps1".
The Fast Retry exit code tells ConfigMgr to retry the installation quicker than it normally would according to your Client Settings. I've seen it retry every 2 hours in the AppEnforce.log, though I heard from a knowledgeable source it could be as fast as 20 minutes. The idea is to have it periodically check if IE is open, and when its closed, to start the install.

You can modify the script if you want to uninstall versions that I am not removing. I remove the 64-bit versions with a 64-bit deployment, I like to treat them as separate applications because that works best in our organization. So for the 64-bit version, you would change the if statement line to match:
if (($javaInstall.Productname -match "(64-bit)") -and ($javaInstall.Productname -notmatch "Development Kit")) {

Create your Java application deployment like normal. I call mine "Oracle JRE 1.8 x86 Silent Install". For the Installation program, I use a command line like "powershell.exe -ExecutionPolicy Unrestricted -File install_jre_x86.ps1"

No comments:

Post a Comment