Most recent versions write to the registry:
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft
You can look for what keys are in there and get out the path using reg.exe
Most recent versions write to the registry:
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft
You can look for what keys are in there and get out the path using reg.exe
Couldn't you use the 'where' command? As in:
>where java
And test against this?
Example:
C:\Users\myname>where java
C:\Program Files (x86)\Java\jdk1.6.0_17\bin\java.exe
C:\Users\myname>where foo
INFO: Could not find files for the given pattern(s).
Using reg[.exe] you can query possible JRE candidates that are installed on the system. There could be none or could be several.
On a test set-up, running inside the command shell:
reg query "HKLM\Software\JavaSoft\Java Runtime Environment"
I get three result lines, of which the first is
CurrentVersion REG_SZ 1.6
Based on that, querying
reg query "HKLM\Software\JavaSoft\Java Runtime Environment\1.6\"
Gives me JavaHome REG_SZ C:\Program Files\Java\jre6
It's much more efficient than scan a file system to find a java binary.
This was tested under a virtual installation of Windows XP 32-bit.