Note: Forums will be making significant UX changes to address key usability improvements surrounding search, discoverability and navigation. To learn more about these changes please visit the announcement which can be found HERE.

Answered Get most current Java version

  • Wednesday, November 14, 2012 9:59 PM
     
      Has Code

    Am trying to get the most current Java version installed on our machines through the WMI interface. If I only ask it for installed Java versions greater than ver 6.0, I get a list of all installed versions. I'd like to take the output and compare it to the next item in the collection to see which is higher, then compare that to the next line, and then give me the highest version as the final output. The script I've got so far is:

    strComputer = "." JavaVer = 6

    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set Collection = objWMIService.ExecQuery("select Name,Version from " _ & "Win32_Product where name like '%Java%' and version > 6") For Each Item In Collection set Javaver1 = item.version If Javaver1 > Javaver Then Javaver = Javaver1 end If next WScript.Echo Item.Name & "," & Javaver

    But it gripes at me saying (7, 4) Microsoft VBScript runtime error: Object required '[string: "7.0.90"]'

    Where is the error? 

    Thanks again guys!!

All Replies

  • Wednesday, November 14, 2012 10:11 PM
     
     Answered Has Code

    Never mind. I figured it out...

    strComputer = "."
    JavaVer = "6"
    JavaName = "Java"
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set Collection = objWMIService.ExecQuery("select Name,Version from " _
      & "Win32_Product where name like '%Java%' and version > 6")
    For Each Item In Collection
       Javaver1 = item.version
       JavaName1 = item.name
    If Javaver1 > Javaver Then
       Javaver = Javaver1 
       JavaName = Javaname1
    end If
    next
    WScript.Echo JavaName & "," & Javaver