We help IT Professionals succeed at work.

VBScript to determine Java version

ednetman
ednetman asked
on
6,721 Views
Last Modified: 2008-05-15
I need to determine the version of Java installed on various machines.  I have tried using GetFile Version:

---------------------------------------------------------------------------------
strComputer = "."
Dim java_ver
On error resume Next

Set objFSO = CreateObject("Scripting.FileSystemObject")
java_ver = objFSO.GetFileVersion("C:\WINNT\system32\java.exe")

WScript.Echo java_ver
---------------------------------------------------------------------------------

This returns 5.0.20.9, but what I am looking for is a value of: java version "1.5.0_02"  I can get this from a command prompt or from the "Full Version" section in the file properties.  I will be porting the value somewhere else, so I can't sort through all the extra info that the command java -version generates.  At least not without some way of cleaning it up.

Thanks!
Comment
Watch Question

Commented:
This should give you what you need (and a few things you don't need)

http://www.devx.com/vb2themax/Tip/18983

Shane Russell2nd Line Desktop Support

Commented:
Check here for the different methods :

http://www.javatester.org/version.html

Two methods suggested there may be able to be scripted such as using jview.exe ( Just shell that exe from vbscript or maybe it has some switches to output that to a text file ) Also there is the java -version and that outputs what version of java unless java isnt installed in which case you get an error message along the lines of :

" 'java' is not recognized as an internal or external command"

I lost the exact error message but generally speaking if you get something like that there is a possibility that it isnt installed so basically needs to be installed.

so something like jview > c:\output.txt

Although jview does not work well with windows 2000 ( which is what I am using now )

Maybe someone else can figure out how to get java -version to output to a txt file correctly cos it just writes a blank file when I try to do it on windows 2k, must be missing something here :)

Author

Commented:
Thanks guys,  the first link was a little too much for me novice abilities to decipher.  The second links was cool, but not really scritable, that I know of.  I need to run a VBScript that will output the version of Java, and nothing else.  There is another app that will be looking for the data, and won't be able to strip off anything extra.

Author

Commented:
Is there a way to run this command:

dir "C:\Program Files\Java"/b

And then have the output stored in an array?  If I could get it to write to a text file, then I can get it to work as well, but the command hasn't worked right.  I think it is bcause of the quotes.  If so, I think I can do that because the folders are named for the java vesrion, and this would output all folders.  That would show us the machines that have multiple versions of Java on them.

Author

Commented:
Anyone?
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Whoo Hooo!!!!!  It worked!

Here is the final code, for anyone else interested:

dim arr()

redim arr(0)
i = 0

sFolder = "C:\Program Files\Java"

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(sFolder)  
Set fc = f.Files
Set ff = f.SubFolders  

For Each f1 in ff
  redim preserve arr(i)
  arr(i) = f1.name
  i = i+1
Next  

For Each f1 in fc
  redim preserve arr(i)
  arr(i) = f1.name
  i = i+1
Next  

For i=0 To UBound(arr,1)
WScript.echo arr(i)
Next
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.