Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect whether Java runtime is installed or not

Tags:

java

c#

runtime

I program windows applications using Java and this builds a ".jar" file not an ".exe" file. When a client computer with no java runtime installed opens the ".jar" file, it runs as an archive with winrar. All I want to know is how to detect whether java runtime is installed or not on a computer using c# code in order to show a MessageBox telling user to install java runtime, or launches the ".jar" file using the java runtime if it's installed.

like image 902
Hazem Avatar asked Dec 06 '09 17:12

Hazem


People also ask

How do I know where JRE is installed?

Click the Advanced tab, and then click Environment Variables. Under System Variables, look for the JAVA_HOME system variable. The JAVA_HOME path should point to the location that you recorded when you installed the JRE.

What version of Java Runtime do I have?

Click the Java tab. In the Java Application Runtime Setting box, click View. The JNLP Runtime Settings dialog box is displayed. Make a screenshot of the listed Java versions or write them down.


1 Answers

You can check the registry

RegistryKey rk = Registry.LocalMachine;
RegistryKey subKey = rk.OpenSubKey("SOFTWARE\\JavaSoft\\Java Runtime Environment");

string currentVerion = subKey.GetValue("CurrentVersion").ToString();
like image 153
h4rp0 Avatar answered Oct 22 '22 01:10

h4rp0