Jump to content

Recommended Posts

Posted (edited)

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

 

 

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

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


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


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')
    FileClose($file)

 

Expand  

 

Edited by Duck
Posted

 

 

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • 2 weeks later...
Posted (edited)

Hi

Have a look at the VersionCompare() function.

 

Regards, Rudi.

Edited by rudi

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

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
×
×
  • Create New...