The java version installed on a PC can be determined by typing
java -version
on a command prompt, but this information is difficult to access through VBScript. I recently put together an installation that put java files into the java version currently installed. This meant finding out which one was the current version, so I put together the following VBScript to compare the version of java.exe in system32 with all java.exe files inside C:\Program Files\Java
Set oShell = CreateObject(“WScript.Shell”)
Set oFSO = CreateObject(“Scripting.FileSystemObject”)
sFile = oShell.ExpandEnvironmentStrings(“%systemroot%”) & “\system32\java.exe”
version = oFSO.GetFileVersion(sFile)
PFDir = oShell.ExpandEnvironmentStrings(“%programfiles%”)
javaDir = PFDIR & “\Java”
Set oFolder = oFSO.GetFolder(javaDir)
Set colFolders = oFolder.SubFolders
For Each folder In colFolders
thisver = oFSO.GetFileVersion(folder & “\bin\java.exe”)
If thisver = version Then
JavaVersion= folder & “\”
End If
Next
As I was doing this inside a custom action in an msi, I changed the variable JavaVersion to Session.TargetPath(“INSTALLDIR”)