I am writing a launcher in C++ to launch my java based GUI application on Windows. I am using CreateProcess
to launch "javaw.exe". Everything works except for the fact that 32-bit version of "javaw.exe" is always launched.
When java is installed, it puts the executables "java.exe" and "javaw.exe" in %windir%\System32
on 32-bit windows. On 64-bit windows, it puts the same executables in %windir%\SysWow64
.
There are 3 possibilities:
32-bit launcher executed on 32-bit windows: %windir%\System32
is in search path, and 32-bit javaw.exe is found. The GUI launches. Everything works.
32-bit launcher executed on 64-bit windows: %windir%\System32
is in search path. %windir%\System32
is redirected to %windir%\SysWow64
(since my launcher is 32 bit in this case). 32-bit javaw.exe is found. The GUI launches. Everything works.
64-bit launcher executed on 64-bit windows: %windir%\System32
is in search path. No redirection happens. It does not contain the executable javaw.exe. The launcher fails.
How do I launch 64-bit javaw.exe in the third case?
I finally found a solution (by digging through various posts on stackoverflow).
Recent versions of JRE when installed do put a copy of "javaw.exe" in System32. The previous versions of 64 bit JRE probably didn't (not sure).
In any case, the registry key HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java Runtime Environment
has a property CurrentVersion
which points to the key for the default JRE for the system. The sub-key corresponding to the version number has a property JavaHome
which points to the location of JRE installation.
If JRE/JDK is not installed, then the Java Runtime Environment
key won't be found.