How to detect the presence and location of the JVM in Windows?

I am trying to determine if the JVM is installed and where it is located, so I can run java.exe .

All I managed to find was HKCU\Software\JavaSoft\Java Runtime Environment\<ver> . Can it be assumed that it is set to %PROGRAMFILES%\Java\jre<ver> ?

I am trying to do this in C #, but I assume that the answer is pretty language inactive, so any answer is appreciated.

EDIT: Ok, silly me, I found How to determine if java runtime is installed or not on a computer using C # , which pointed me to HKLM\Software\JavaSoft\Java Runtime Environment\CurrentVersion , which works with HKLM\Software\JavaSoft\Java Runtime Environment\<ver>\JavaHome . I managed to find them instead of HKLM\Software\Wow6432Node\JavaSoft\Java Runtime Environment . Is there a way to determine which ones I should check without trying to smell the type of processor?

+8
java windows jvm
source share
4 answers

I am going to throw my hat in a ring with a code that I ended up using:

 string javaDirectory = null; // Native registry key - 32b on 32b or 64b on 64b // Fall back on 32b Java on Win64 if available RegistryKey javaKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Javasoft\\Java Runtime Environment") ?? Registry.LocalMachine.OpenSubKey("SOFTWARE\\Wow6432Node\\Javasoft\\Java Runtime Environment"); if (javaKey != null) { string javaVersion = javaKey.GetValue("CurrentVersion").ToString(); try { javaDirectory = javaKey.OpenSubKey(javaVersion).GetValue("JavaHome").ToString(); } catch(NullReferenceException) { /* Ignore null deref, means we can't get a directory */ } } if (javaDirectory == null) { // deal with a lack of Java here. } 
+4
source share

A properly installed JVM on a Windows system (most likely ..) will respond to a shell command:

 java -version 

This does not return the path, but try

 java -verbose -version 

(at least) one of the lines will contain the substring rt.jar , and this line contains the path to the "active" Java virtual machine.

+2
source share

Doesn't the JRE install java.exe in c: \ windows?

0
source share

You can try to get the environment variable * * JAVA_HOME *.

This may be helpful.

EDIT:

Better think of the "CLASSPATH" variable.

 ------- start -------- C:\Documents and Settings\david>set ALLUSERSPROFILE=... APPDATA=... CLASSPATH=.;C:\Archivos de programa\Java\jre6\lib\ext\QTJava.zip CommonProgramFiles=... ... ----- end ---- 
-one
source share

All Articles