Solved

find JRE version

Posted on 2006-06-09
17
2,806 Views
Last Modified: 2008-01-09
how can i find and display the JRE version installed on machine?
0
Comment
Question by:ellandrd
  • 8
  • 4
  • 3
  • +1
17 Comments
 
LVL 10

Accepted Solution

by:
0h4crying0utloud earned 500 total points
ID: 16869932


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
 
LVL 35

Expert Comment

by:TimYates
ID: 16870007
of course, the javascript will not work until the applet has fully loaded...
0
 
LVL 16

Author Comment

by:ellandrd
ID: 16870074
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
 
LVL 16

Author Comment

by:ellandrd
ID: 16870121
>>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
 
LVL 10

Expert Comment

by:0h4crying0utloud
ID: 16870149

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
 
LVL 16

Author Comment

by:ellandrd
ID: 16870561
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
 
LVL 35

Expert Comment

by:TimYates
ID: 16870622
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 16870646
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 16

Author Comment

by:ellandrd
ID: 16870659
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
 
LVL 16

Author Comment

by:ellandrd
ID: 16870766
sorry tim didnt see your post.

ya 1.5 would do... i wasnt thinking while i typed a reply....
0
 
LVL 16

Author Comment

by:ellandrd
ID: 16870820
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
 
LVL 16

Author Comment

by:ellandrd
ID: 16870838
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
 
LVL 16

Author Comment

by:ellandrd
ID: 16870887
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 16870964
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
 
LVL 35

Expert Comment

by:TimYates
ID: 16870984
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 16871086
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
 
LVL 35

Expert Comment

by:TimYates
ID: 16871829
<Applet id="app" Code="HelloWorld.class" width="150" height="50" MAYSCRIPT></Applet>

?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now