NOTE: For one of my clients, we are phasing out the deployment of the JRE on their Windows clients. The settings reflected below are used to create two versions of the Install.cmd script - one to perform a forced install and one that only installs if an existing installation of the JRE is found. The purpose behind this is to handle the limited targeting of Intune. For the force install version, it is advertised as an "available install" to users who require the JRE on their systems. The upgrade-if-found version is advertised as a "required install" to all managed systems, which will force an upgrade and then report success, but only on those systems with the JRE actually installed.

Obtain Installation Source

  • Go to the Java Download page and download the Windows Offline version. Select a version that matches your browser (typically, the 32-bit one). The code on this page does not distinguish between 32-bit and 64-bit editions and, in fact, you shouldn't install both on your computer at the same time (there is a problem with the control panel applet when you have both installed - the applet only manages settings for one of them but not the other).
  • Launch the EXE that was downloaded, but do not click anything when the initial dialog box appears. Instead, drop down to an elevated command prompt while that dialog is still visible. We need to grab the MSI file that is unpacked while the installer is running.
  • cd /d %APPDATA%\..\LocalLow\Oracle\Java
  • Look for a subfolder for the latest version (something like jre1.8.0_65) and cd into that folder.
  • Copy the MSI that is there into a new folder that you will use as the source of the package flat files.
  • Exit the command prompt (to release any folder locks) and then cancel out of the installation EXE dialog box that has been waiting in the background.

Install.cmd and Update.cmd

Copy the Install.cmd from a prior installation or create a new one from this page and make the following changes.

  • Replace all instances of SoftwareName with Oracle Java Runtime
  • Replace all instances of Version with the version and update number.
  • Verify the correct version number on the cscript //NOLOGO CheckVersion.vbs /MinVer:A.B.C.D line. NOTE: Oracle seems to do this by using the following format: Major.0.Update0. So, version 8 update 65 would be 8.0.650.
  • In the :UninstallPrevious section, use the following commands to uninstall previous versions of the JRE:
taskkill /im iexplore.exe /f 1>nul
taskkill /im chrome.exe /f 1>nul
taskkill /im firefox.exe /f 1>nul
taskkill /im java.exe /f 1>nul
wmic product where 'Name like "%%Java%%Update%%"' call Uninstall /NoInteractive
  • In the :Install section, use the following command to install the JRE (update the MSI file name with the correct version):
msiexec /i "%~dp0jre1.8.0_65.msi" /qb!- /norestart JU=0 JAVAUPDATE=0 AUTOUPDATECHECK=0 RebootYesNo=No WEB_JAVA=1
  • In the :Configure section, add the following lines:
reg add "HKLM\Software\JavaSoft\Java Update\Policy" /v EnableJavaUpdate /t REG_DWORD /d 0x0 /f 1>nul 2>nul
if .%Processor_Architecture%.==.AMD64. reg add "HKLM\Software\Wow6432Node\JavaSoft\Java Update\Policy" /v EnableJavaUpdate /t REG_DWORD /d 0x0 /f 1>nul 2>nul
reg delete HKLM\Software\Microsoft\Windows\CurrentVersion\Run /v SunJavaUpdateSched /f 1>nul 2>nul
reg delete HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Run /v SunJavaUpdateSched /f 1>nul 2>nul
  • In the :MarkupRegistry section, ensure that there is an entry for the current version of Java being installed.
  • Save this Install.cmd file and, while still in Notepad (or whatever editor), save the file as Update.cmd.
  • Up in the section that checks for the current version of the JRE, in the clause if %DT% EQU 2 (, change the goto line from goto :Install to goto :MarkupRegistry.
  • Save the Update.cmd file and close the editor.

CheckVersion.vbs

Copy the CheckVersion.vbs from a prior installation or create a new one from the MSI Version found on this page and set the variables to:

Const Query = "%Java%Update%"
Const VersionValue = "DisplayVersion"

Conclusion

That's it! From here, you can repackage as EXE (do this twice, once for the Install.cmd and once for the Upgrade.cmd versions), and/or deploy it using your favorite software distribution system. For the upgrade version, confirmation of installation is done by checking only for the registry key. For the install version, check the MSI key associated with the MSI file.