• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2831
  • Last Modified:

find JRE version

how can i find and display the JRE version installed on machine?
0
ellandrd
Asked:
ellandrd
  • 8
  • 4
  • 3
  • +1
1 Solution
 
0h4crying0utloudCommented:


This is how I do it:

alert("JRE Version: " + document.myApplet.getJavaVersion());

Here's more info:
HOW TO DETECT Java Plugin from JavaScript:
http://forum.java.sun.com/thread.jspa?threadID=168544&start=0
0
 
TimYatesCommented:
of course, the javascript will not work until the applet has fully loaded...
0
 
ellandrdAuthor Commented:
see i dont think this will work for me.

ive got webpage X that uses an applet and redirects to webpage Y.

but what ive found is that webpage X wont work (applet dont get loaded webpage X hangs) unless the user has an JRE installed, hence why i want to check for an JRE first but trying to load & start applet.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ellandrdAuthor Commented:
>>hence why i want to check for an JRE first but trying to load & start applet.

should read

hence why i want to check for an JRE first before trying to load & start applet.
0
 
0h4crying0utloudCommented:

Here's an excerpt from one of the comments in the sun developer forum: Note the IE stipulation


Try following java script, it works on new browsers (NS 4+, IE5+). For IE you have to enable 'ActiveX objects creation' in security options.


var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);


var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
&& (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var is_nav4up = (is_nav && (is_major >= 4));

var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5_5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_ie6 = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.0") !=-1));
var is_ie5up = (is_ie && (is_major == 4)
&& ( (agt.indexOf("msie 5.0")!=-1)
|| (agt.indexOf("msie 5.5")!=-1)
|| (agt.indexOf("msie 6.0")!=-1) ) );

var pluginDetected = false;
var activeXDisabled = false;

// we can check for plugin existence only when browser is 'is_ie5up' or 'is_nav4up'
if(is_nav4up) {
// Refresh 'navigator.plugins' to get newly installed plugins.
// Use 'navigator.plugins.refresh(false)' to refresh plugins
// without refreshing open documents (browser windows)
if(navigator.plugins) {
navigator.plugins.refresh(false);
}

// check for Java plugin in installed plugins
if(navigator.mimeTypes) {
for (i=0; i < navigator.mimeTypes.length; i++) {
if( (navigator.mimeTypes[ i].type != null)
&& (navigator.mimeTypes[ i].type.indexOf(
"application/x-java-applet;jpi-version=1.3") != -1) ) {
pluginDetected = true;
break;
}

}
}
} else if (is_ie5up) {
var javaVersion;
var shell;
try {
// Create WSH(WindowsScriptHost) shell, available on Windows only
shell = new ActiveXObject("WScript.Shell");

if (shell != null) {
// Read JRE version from Window Registry
try {
javaVersion = shell.regRead("HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment\\CurrentVersion");
} catch(e) {
// handle exceptions raised by 'shell.regRead(...)' here
// so that the outer try-catch block would receive only
// exceptions raised by 'shell = new ActiveXObject(...)'
}
}
} catch(e) {
// Creating ActiveX controls thru script is disabled
// in InternetExplorer security options

// To enable it:
// a. Go to the 'Tools --> Internet Options' menu
// b. Select the 'Security' tab
// c. Select zone (Internet/Intranet)
// d. Click the 'Custom Level..' button which will display the
// 'Security Settings' window.
// e. Enable the option 'Initialize and script ActiveX controls
// not marked as safe'

activeXDisabled = true;
}

// Check whether we got required (1.3+) Java Plugin
if ( (javaVersion != null) && (javaVersion.indexOf("1.3") != -1) ) {
pluginDetected = true;
}
}


if (pluginDetected) {
// show applet page
} else if (confirm("Java Plugin 1.3+ not found, Do you want to download it?")) {
// show install page
} else {
// show error page
}
0
 
ellandrdAuthor Commented:
Ok half working...

i use 1.5.0_07 and im forcing all users to be the same...

my reg key is:

HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment\\1.5.0_07


i have tried this but dont work:

javaVersion = (shell.regRead("HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment\\1.5.0_07")) ? "1.5.0_07" : "1.3" ;


                  
                  
0
 
TimYatesCommented:
why 1.5.0_07?

Surely just "1.5.0" or better would do?

Forcing people to use a particular update of a particular version seems a little restrictive (and harsh)
0
 
Michel PlungjanIT ExpertCommented:
Why not

 javaVersion = shell.regRead("HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment\\CurrentVersion");
if (javaVersion !='1.5.0_07') { alert('Nope'); javaVersion='1.3'; }
else ...
0
 
ellandrdAuthor Commented:
because i dont have a folder called "CurrentVersion" in my registry...

after HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment\\

i have a folder "1.5" & another folder "1.5.0_07"
0
 
ellandrdAuthor Commented:
sorry tim didnt see your post.

ya 1.5 would do... i wasnt thinking while i typed a reply....
0
 
ellandrdAuthor Commented:
ok the script isnt even getting to that point.

ive insertted some debugging statements and the script stops right before:

document.writeln("here");

// we can check for plugin existence only when browser is 'is_ie5up' or 'is_nav4up'
if(is_nav4up)
{
   ...

on my page, the only statement i see is "here"...

im actually testing this on IE7, but my users use IE5+
0
 
ellandrdAuthor Commented:
ok, i tested it in IE5+ and it now fails here:

// Create WSH(WindowsScriptHost) shell, available on Windows only
shell = new ActiveXObject("WScript.Shell");



any idea's?
0
 
ellandrdAuthor Commented:
OK, i cannot get script to work as the security build into IE7 wont allow webpage to be run with initialize and script ActiveX controls enabled, but IE5+ will so i now have want i want working...

just let me give it a few more tests before i accept...

ellandrd
0
 
Michel PlungjanIT ExpertCommented:
How do you get


alert("JRE Version: " + document.myApplet.getJavaVersion());

to work????

I get Object does not support....

<HTML>
<Head>
<Title> A Simple Program </Title>
<script>
function showStuff() {
showIt=true
  var x = document.getElementById('app');
  txt = "";
  try {
    txt += 'version:'+x.getJavaVersion()

    for (i in x) {
      txt +='<hr>'+i
      if (i!='outerHTML') txt +=':<br>'+((x[i])?x[i]:'not set')
     }
     txt+='<hr>'
  }
  catch(e) { alert(e.message)}
  document.getElementById('resu').innerHTML=txt;
}
</script>
<Body onLoad="showStuff()">
<Applet id="app" Code="HelloWorld.class" width="150" height="50"></Applet>
<div id="resu"></div>

</Body>
</HTML>

0
 
TimYatesCommented:
You can't call it onload

You have to call it after the applet is loaded (via a link or timer or something)

I *think* that's the problem...
0
 
Michel PlungjanIT ExpertCommented:
Nope

<HTML>
<Head>
<Title> A Simple Program </Title>
<script>
function showStuff() {
showIt=true
  var x = document.getElementById('app');
  txt = "";
  try {
    txt += 'version:'+x.getJavaVersion()

    for (i in x) {
      txt +='<hr>'+i
      if (i!='outerHTML') txt +=':<br>'+((x[i])?x[i]:'not set')
     }
     txt+='<hr>'
  }
  catch(e) { alert(e.message)}
  document.getElementById('resu').innerHTML=txt;
}
</script>
<body onLoad="setTimeout('showStuff()',2000)">
<Applet id="app" Code="HelloWorld.class" width="150" height="50"></Applet>
<div id="resu"></div>

</Body>
</HTML>
0
 
TimYatesCommented:
<Applet id="app" Code="HelloWorld.class" width="150" height="50" MAYSCRIPT></Applet>

?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 8
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now