Unable to read from Process.StandardOutput-Collection of common programming errors
You can read the currently installed Java version from the registry as well. The following file includes the method TryGetJavaHome, which supports 32- and 64-bit virtual machines for specific vendor/installation combinations.
bool TryGetJavaHome(
RegistryView registryView,
string vendor,
string installation,
out string javaHome)
Vendors:
- “JavaSoft” (HotSpot)
- “JRockit”
Installations:
- “Java Runtime Environment”
- “Java Development Kit”
If you look at the code for the method, you’ll find the following line which obtains the current version.
object currentVersion = javaKey.GetValue("CurrentVersion");
This will return a value like “1.7” or “1.6”. If want a more complete version number, some installations provide the following.
object familyVersion6 = javaKey.GetValue("Java6FamilyVersion");
object familyVersion7 = javaKey.GetValue("Java7FamilyVersion");
For some installations, the family version is not present, but for the standard runtime installation I see the values “1.6.0_38” and “1.7.0_13”.
Reference: Antlr4ClassGenerationTaskInternal.cs