0

How to check, java is installed on windows system and get fullpath from jvm.dll on client folder?

I used this code, but i dont know how to retrive the current version

TRegistry* reg = new TRegistry(KEY_READ);
reg->RootKey = HKEY_CURRENT_USER;
reg->Access = KEY_ALL_ACCESS;
bool openResult = reg->OpenKey("SOFTWARE\\JavaSoft\\Java Runtime Environment", true);
if(!openResult) // cannot create registry keys, use default values
    return;
if(!reg->ValueExists("CurrentVersion")) //it's not exist CuurentVersion
    return;

2 Answers2

0

I don't think writing some code or anything like that is needed to see if java is installed. To see if its installed on windows just go to C:\Program Files\Java if that directory exists then you have java, if its installed on a different directory look in windows programs and it should show if java is installed, if not then you most likely don't have java. Use this link to see what version you have, but it is recommended to always get the latest version.

Hope this helps, Luke

Edit:

If you want to see if java is installed on another computer programmatically try using a .bat file to see, this link should help. or use jsmooth to build the jar into an .exe, with this, if java is not installed it will prompt the user to install java.

Community
  • 1
  • 1
Luke Melaia
  • 1,470
  • 14
  • 22
0

You can execute a system "Java -version" command from your code. Here is an example for C++. To find the version you just need to parse the result you get, if you get. The String result would provide the information you required.

enter image description here

Meanwhile, to find the path i believe you can do it by iterating through environmental variables and look for JAVA_HOME.

Community
  • 1
  • 1
eldjon
  • 2,800
  • 2
  • 20
  • 23
  • I would opt for using `JNI_CreateJavaVM()` and `JNIEnv::GetVersion()` instead of parsing a command-line output. And you don't need to "iterate" through environment variables, most platforms provide a way to query the value of a specific variable by its name. On Windows, it is [`GetEnvironmentVariable()`](http://msdn.microsoft.com/en-us/library/windows/desktop/ms683188.aspx). However, Windows does not use `JAVA_HOME` (at least, there is no `JAVA_HOME` variable on my system, even though Java is installed). – Remy Lebeau Sep 03 '14 at 00:07
  • regarding JAVA_HOME you are right: its not guaranteed to work. the first suggestion is quite a valid one, so i believe you should post it as one alternative of possible solutions. – eldjon Sep 03 '14 at 15:09