Since some days the JRE is installed in a version specific directory [1].
So I tried to write a DOS batch or VBS script to determine the location of the latest installed JRE 8 32 bit.
But when checking the registry key "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft" i noticed that this contains only information regarding the 64 Bit Java Runtime.
So any idea how to determine the location of the latest installed 32 Bit Java Runtime via DOS or vbs? This should also consider that a 64 Bit version might be installed in parallel on the system.
An alternative might be a file search in the directory C:\Program Files (x86)\Java. But Java Runtime might not be installed in this directory.
[1] http://www.oracle.com/technetwork/java/javase/8u20-relnotes-2257729.html
JRE Installation Directory Starting with JDK 8u20 release, the JRE will be installed in a version specific directory. For example: C:\Program Files\Java\jre1.8.0_20
The version specific directory naming is intentional and it does not indicate that the JRE install is static. As with the earlier releases, static JRE install is performed only if STATIC=1 option is passed (via command line or config file) by the user.
Edit: Frank's solution is the correct one. See my addition to his answer.
Previous answer: How about scraping the location from the start menu shortcut? The shortcut should always be in the All Users Start Menu → Programs unless a user manually deletes it, which in nearly two decades of desktop support I can't say I've ever seen happen. The shortcut should always point to the default instance of Java, even if there are multiple versions installed. And the installer has no option for the end user to forego creation of the start menu shortcuts.
Anyway,
wmic path win32_shortcutfile
can read the target of a shortcut.As commented below, the Start Menu shortcuts could point to the 64-bit install of Java. If that's the case, then fall back to searching
%PROGRAMFILES(x86)%
forjava.exe
.As I found out the 64 Bit Java Runtime Installation does not override the registry keys of the 32 bit Version. If you use the 32 bit Version of regedit.exe you will find the registry keys which belong to the 32 bit Java Runtime Environment Installation.
So the following Batch file should solve the above issue:
contribution from rojo:
The above script illustrates the correct idea, but exporting a .reg file and scraping it can be a bit cumbersome. Here's the same idea, but using
%windir%\syswow64\reg.exe query
to query the registry values in-line: