I'm writing a complex setup/installer application in native C++/MFC. I would very much like to be able to detect the version of Java that is installed (if any).
Is this possible, and so, how?
I'm writing a complex setup/installer application in native C++/MFC. I would very much like to be able to detect the version of Java that is installed (if any).
Is this possible, and so, how?
Fork a process that executes the following command: java -version
. Collect the output and parse it. It looks something like the following:
java version "1.5.0_16"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-284)
Java HotSpot(TM) Client VM (build 1.5.0_16-133, mixed mode, sharing)
You could try running java -version
in a subprocess (reading that process's output with pipe) and parsing the results (if any); or, you could mess with Windows' registry (which feels even more complicated, but may be less kludgy).
Keep in mind also that it is entirely possible to have more than one JRE installed on a machine at the same time. If your install program detects more than one JRE, it should offer a choice to the user rather than assuming that one of them (eg. the latest one) should be the one which will be used by your app.
I would suggest to use the registry. You're programming windows, so do it windows-way. Registry-anxiety is irrational.
Registry key for the version:
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\CurrentVersion
Information how to get the value from the registry can be found here.
Information about other java related registry keys can be found here.