Link to home
Start Free TrialLog in
Avatar of ellandrd
ellandrdFlag for Ireland

asked on

find JRE version

how can i find and display the JRE version installed on machine?
ASKER CERTIFIED SOLUTION
Avatar of 0h4crying0utloud
0h4crying0utloud

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TimYates
of course, the javascript will not work until the applet has fully loaded...
Avatar of ellandrd

ASKER

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.
>>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.
Avatar of 0h4crying0utloud
0h4crying0utloud


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
}
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" ;


                  
                  
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)
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 ...
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"
sorry tim didnt see your post.

ya 1.5 would do... i wasnt thinking while i typed a reply....
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+
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?
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
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>

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...
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>
<Applet id="app" Code="HelloWorld.class" width="150" height="50" MAYSCRIPT></Applet>

?