Jump to content
Sign in to follow this  
jhinesyo

Java Version- Detect & / or Install

Recommended Posts

jhinesyo

Hello,

I'm looking for the correct way to determine / read the version(s) of Java JRE installed on the machine running my script.

A program I use at work requires at least Java RE 1.4.2_13 or higher ( but less than the new Java RE v5 )

My current autoit script looks for Java as follows:

CODE

;Check if Java already installed

If FileExists ( @ProgramFilesDir & "\Java\j2re1.4.2_13\bin\java.exe" ) Then

$javainst = "no"

EndIf

;install/not install java

While $javainst = "yes"

;display java install graphic

SplashImageOn("Attention", $destination2, 300, 120)

;get java 1.4.2_13 from local intranet server and save in root

InetGet("http://intranet/java/java.msi", "c:\java.msi", 0, 0)

;install java silently

RunWait("msiexec.exe" & " /i" & "c:\java.msi /qn", "C:", @SW_Hide)

SplashOff()

$javainst = "no" ;flagged tripped, exit install loop

;catch errors by un-downloaded file

If @InetGetBytesRead = -1 Then

MsgBox(1,"Warning! - Installer","Unable to download and/or install Java 1.4.2_13. Please call the integrated support center")

Exit

EndIf

Wend

I would like to be able to have the program not download and install java if a higher version of Java is already installed ( could save the users many minutes ).

I'm looking for a way to "read" the current version of java installed, there could be more than one installed too. I would like to evaluate which is the highest appropriate version and then have a variable set to know the path to this java so I can call it later to launch my java program.

Does this make sense?

thanks everyone!

Share this post


Link to post
Share on other sites
Gif

if i understood correctly you should use FileINSTALL() and also look here...

Share this post


Link to post
Share on other sites
Gif

if i understood correctly you should use FileINSTALL() and also look here...

OK.... this and exacly FileGetVersion()

example:

$ver = FileGetVersion("Explorer.exe")
MsgBox(0, "Explorer version", $ver)

should be fine...

Edited by c4nm7

Share this post


Link to post
Share on other sites
jhinesyo

Java.exe and javaws.exe both report back as 0.0.0.0 - I'm guessing I need to use the FileFindFirst and search out the subdirectories within c:\program files\java to determine which versions are locally installed.

Anyone have any better ideas?

OK.... this and exacly FileGetVersion()

example:

$ver = FileGetVersion("Explorer.exe")
MsgBox(0, "Explorer version", $ver)

should be fine...

Share this post


Link to post
Share on other sites
Gif

Java.exe and javaws.exe both report back as 0.0.0.0 - I'm guessing I need to use the FileFindFirst and search out the subdirectories within c:\program files\java to determine which versions are locally installed.

Anyone have any better ideas?

or search if there is any value in regedit (there should be)

Share this post


Link to post
Share on other sites
ksmith247

I couldn't tell you how to code it off the top of my head but could you kick off a command prompt, do a java -version and dump the output to a text file and then read that file to determine what version is active? Otherwise you will have to parse every directory under Program Files\java. Remember that just because a new version is installed doesn't necessarily make it the version that is in use. java -version will tell you that.


Support bacteria; it's the only culture most people have.LxP's Learning to Script with AutoIt 3 - Excellent starting placeVolly's Links Page - Links to cool and useful scriptsAutoIt Wrappers - Valuater's AutoIt Wrappers post. Lots of good stuff.Support AutoIt - Make a donation here; I did.[size="2"]#include <Guinness.pint>[/size]

Share this post


Link to post
Share on other sites
The Kandie Man

This works on the latest version of Java for determining the version. Pretty sure it will work for the older versions as well.

$s_version = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment","BrowserJavaVersion")
Msgbox(0,"Current Java Browser Version",$s_version)
$s_version = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment","CurrentVersion")
Msgbox(0,"Current Java Version",$s_version)

Try this and see if it correctly detects the older versions as well.

- The Kandie Man ;-)


"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites
jhinesyo

thanks TKM, I'm going to test the code tomorrow and see what happens!

This works on the latest version of Java for determining the version. Pretty sure it will work for the older versions as well.

$s_version = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment","BrowserJavaVersion")
Msgbox(0,"Current Java Browser Version",$s_version)
$s_version = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment","CurrentVersion")
Msgbox(0,"Current Java Version",$s_version)

Try this and see if it correctly detects the older versions as well.

- The Kandie Man ;-)

Share this post


Link to post
Share on other sites
jhinesyo

thanks again! It works, give the major version only, but it is what I was looking for.

thanks!

Share this post


Link to post
Share on other sites
The Kandie Man

Glad I could be of help.

- The Kandie Man ;-)


"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites
star2

or search if there is any value in regedit (there should be)

THIS IS what I need to remember always

I keep on forgetting this

thanks

see ya


[quote]Baby you're all that I want, When you're lyin' here in my armsI'm findin' it hard to believe, We're in heavenAnd love is all that I need , And I found it there in your heartIt isn't too hard to see, We're in heaven .Bryan Adams[/quote].............................................................................[u]AUTOIT[/u]

Share this post


Link to post
Share on other sites
Selmak

On older Microsoft versions, 'JVIEW' returns version info to the console.

Share this post


Link to post
Share on other sites
jhinesyo

Thanks guys!

I found that I do need the full major+minor version information, so I used the following code to scan the program files\java dir to find all installed versions, then check them against "valid" version that the software runs in.

CODE

;;;variable placeholder

$javavers = ""

$javainst = ""

Dim $dirArray[1]

$counter = 0

;;;;;;;;;;;;

;;find and evaluate the java installed

;;

$pathprog = @ProgramFilesDir

$dirsearch = FileFindFirstFile($pathprog & "\Java\*")

; Check if the search was successful

If $dirsearch = -1 Then

;;;;no java found at all, will be installed later...

EndIf

;found java, stick value into array and keep looking

While 1

$file = FileFindNextFile($dirsearch)

If @error Then ExitLoop

;store dir name in array of names.

_ArrayInsert($dirArray, $counter,$file)

$counter = $counter + 1

WEnd

; Close the search handle

FileClose($dirsearch)

;;;Evaluate current installed Java

;;;sort descending order for eval in select/case

_ArraySort($dirArray, 1)

$counter = 0

For $counter = 0 to UBound($dirArray) - 1

Select

Case String($dirArray[$counter]) = "j2re1.4.2_13"

$javavers = $dirArray[$counter]

ExitLoop

Case String($dirArray[$counter]) = "j2re1.4.2_07"

$javavers = $dirArray[$counter]

ExitLoop

Case String($dirArray[$counter]) = "j2re1.4.2_03"

$javavers = $dirArray[$counter]

ExitLoop

Case Else

;no supported java version is installed, should install java from our install cache, defaulting install variables below.

$javainst = "yes"

$javavers = "j2re1.4.2_13"

EndSelect

$counter = $counter + 1

Next

Now, I need to clean my ugly code, replace the procedural flow with functions and move on from there. Thanks again!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×