Jump to content

Detecting the Newest version of Java currently installed

Recommended Posts


I am having some issue coming up with the logic to detect the latest version of Java installed on a PC via the JRE in C:\Program Files\Java\*
I need to detect the latest version of Java (JRE) to dynamically create a batch file that points to the correct Java version. 

I have already put all the subfolders name's in an array but now i need to find the latest version for my $version variable



;Gift Card Finder
#include <File.au3>
#include <Array.au3>

If FileExists('C:\Program Files\Java\*') Then
        Global $fileList = _FileListToArray('C:\Program Files\Java\', 'jre*')

For $i = 1 To $fileList[0]
    Local $version = StringTrimLeft($fileList[$i],3);Get JRE version number
    ;Local $version = StringReplace($version, '_', '')
    MsgBox(0,'','jre' & $version)

Local $batch = "C:\IT\GiftCardFind.bat"

$file = FileOpen($batch, 1)
        FileWriteLine($file, ' ')
        FileWriteLine($file, '@echo off')
        FileWriteLine($file, 'SETLOCAL')
        FileWriteLine($file, ' ')
        FileWriteLine($file, 'SET JAVA_7_PATH="C:\program files\java\'& $version &'"')
        FileWriteLine($file, ' ')
        FileWriteLine($file, 'SET SHARE=\\srvlpcorp01\GiftCardFinder')
        FileWriteLine($file, 'TITLE Gift Card Finder')
        FileWriteLine($file, 'SET LOG_FILE="C:\Program Files\GCFind\GCFind.Log"')
        FileWriteLine($file, 'SET JAVA_JRE="C:\program files\java\'& $version &'\bin\java.exe"')
        FileWriteLine($file, ' ')
        FileWriteLine($file, 'ECHO Gift Card Finder started %DATE% %TIME% > %LOG_FILE% 2>&1')
        FileWriteLine($file, 'PUSHD %SHARE% >>%LOG_FILE% 2>&1')
        FileWriteLine($file, 'set cpath=.\;.\swing-worker-1.2.jar;.\sqljdbc.jar;.\log4j.jar')
        FileWriteLine($file, '%JAVA_JRE% -cp %cpath%  com.giftcardUtils.GiftCardFinder >> %LOG_FILE% 2>&1')
        FileWriteLine($file, 'POPD >>%LOG_FILE% 2>&1')



Edited by Duck

Share this post

Link to post
Share on other sites




Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-03-17

Share this post

Link to post
Share on other sites


Have a look at the VersionCompare() function.


Regards, Rudi.

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

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

  • Similar Content

    • Rammanan
      By Rammanan
      Hi all, Below is my script,
      Pls advise me if any wrong on that....File exit in location but the return -1.
      FileOpen($file, 0)
         $line = FileReadLine($file)
      Local $aArray = _FileListToArrayRec($serverpath, "*|*.txt", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_NOPATH)
      If @error Then
              MsgBox($MB_SYSTEMMODAL, "Ooops!", "No files found")
          ;_ArrayDisplay($aArray, "Sorted tree")
                 Local $hSearch = FileFindFirstFile($line)
    • XaelloNegative
      By XaelloNegative
      Hi team,
      I have a "well-built" autoIt exe app. Its running smooth until I open another application that when I run through the window info tool, returns as "SunAwtFrame". After running said application, my "well-built" autoIt exe app ceases to run.
      What seems to be the problem here and is there a possible turn around for it? Any suggestion or recommendation will be greatly appreciated. Thanks in advance.
    • Theodoor
      By Theodoor
      I am trying to use the ControlClick in a "save as"-window to select the path of where to save the document.
      I found out that when in press the icon in front of the path, i select the path. So I am trying to press that button (i have attached a print screen of this window).
      While trying to figure out how i had to use the ControlClick, it said somewhere that i could us Au3Info to find out what title,... i should use with the ControlClick.
      The result of the Au3Info I have attached aswel.
      The ControlClick that i tried are these: (and none of these even move the mouse)
      ControlClick("[CLASS:ToolbarWindow32; INSTANCE:4]", "", "", "Left" ,1 ,10,10)
      ControlClick("[CLASS:ToolbarWindow32; INSTANCE:4]", "", "1001", "Left" ,1 ,10,10)
      ControlClick("[CLASS:ToolbarWindow32]", "", "", "Left" ,1 ,10,10)
      ControlClick("Save project as", "", "", "Left" ,1 ,10,10)
      I don't know what I am doing wrong.
      Should I use a controlID? is my windowtitle wrong?
      Can anyone help me?
      Thanks in advance,

    • Mercy
      By Mercy
      I need to add a column with data daily at the end of the column and calculate the difference between last two columns in put it in a seperate column. So i need to get the  position of the last column.
      Local $count = $oWorkbook2.Worksheets(1).UsedRange.Columns.Count MsgBox(0,"",$count) ; ***************************************************************************** ; Copy a single cell from another workbook. Pass the source range as object. ; ***************************************************************************** Local $oRange = $oWorkbook2.Worksheets(1).Range("A1:A15") _Excel_RangeCopyPaste($oWorkbook1.Worksheets(1), $oRange,"H1:H15") _Excel_RangeWrite($oWorkbook1, $oWorkbook1.Worksheets(1), "=C2-H2", "I2:I15", False) this code copies to a specific column H with a range 15. But i need to keep that column range to update automatically when columns are added.
    • Mercy
      By Mercy
      I inspect that Security tab in the webpage .I get the html element below:
      <td tabindex="-1" align="center" class="infaTabsetSimpleTabSetTop" nowrap="true" valign="middle" onfocus="app_details_browse.$47()">Security</td>
      If iam using the class name and trying to click the element. Iam getting "found" but cannot click as all the tab contains same class.
      If iam using the onfocus attribute which is different for every tab and trying to click the element, the element cannot be found.
      Local $oFound = "" Local $oBtns = _IETagNameGetCollection($oIE, "td") For $oBtn In $oBtns ;If String($oBtn.onfocus) ="app_details_browse.$47()" Then If String($oBtn.classname) = "infaTabsetSimpleTabSetTop" Then $oFound = $oBtn EndIf Next If IsObj($oFound) Then _IEAction ($oFound, "focus") _IEAction ($oFound, "click") MsgBox(16, "Success", "found") Else MsgBox(16, "Failed", "Not found.") EndIf


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.