TechKnow

Author Topic: [BAT] Javatector (Latest JRE version detector script)  (Read 852 times)

0 Members and 1 Guest are viewing this topic.

Offline HcH

  • TechKnow Owner, Ethical Hacker
  • Administrator
  • Uber Member
  • *****
  • Posts: 9936
  • Karma: +2284/-111
[BAT] Javatector (Latest JRE version detector script)
« on: January 25, 2016, 10:05:20 AM »
Hello TechKnow members and visitors!

Today, I needed to find out a simple way to set the java path to the latest installed java version on a computer. Well, I can say that I didn't expect it could be this easy! Basically, this is a loop inside a loop, detecting the latest version. This is very handy when you need to set the java directory in path (this does that automatically for the session it's being run in). Just copy the lines from the script below and paste them into notepad, save it as a batch file, call it when you need to retreive or set the java path:

Code: (JAVATECTOR.BAT) [Select]
@echo off
for /L %%I in (6,1,10) do call :JAVA_JDK_VER %%I
:JAVA_JDK_VER
for /L %%J in (1,1,99) do call :JAVA_JDK_UPDATE %1 %%J
:JAVA_JDK_UPDATE
if exist "%ProgramFiles%\Java\jdk1.%1.0_%2\" PATH=%PATH%;%ProgramFiles%\Java\jdk1.%1.0_%2\bin && ECHO. && ECHO JDK %1u%2 FOUND! JDK PATH HAS BEEN SET && ECHO. && PAUSE

And now the script with some notes here and there, explaining how it works:

@echo off We really don't want to see all those possibilities of major version/update coming by.
for /L %%I in (6,1,10) do call :JAVA_JDK_VER %%I Seek through v1.6 to 1.10 *currently v1.8 is the last version
:JAVA_JDK_VER The major version label
for /L %%J in (1,1,99) do call :JAVA_JDK_UPDATE %1 %%J Seek through u1-99
:JAVA_JDK_UPDATE The update label
if exist "%ProgramFiles%\Java\jdk1.%1.0_%2\" PATH=%PATH%;%ProgramFiles%\Java\jdk1.%1.0_%2\bin && ECHO. && ECHO JDK %1u%2 FOUND! JDK PATH HAS BEEN SET && ECHO. && PAUSE if the location is found, set it with the rest of %PATH% to PATH :)

It's certainly very handy to have for my job where some application still use the dreaded java runtime environment and I hope this will help you as well!

Enjoy!

HcH