Last active
July 23, 2023 20:14
-
-
Save Lokno/4a53c597bbceab5095fcdac58795373e to your computer and use it in GitHub Desktop.
Searches for all java.exe executables on the host machine and runs each with the -version flag to display the Java version information.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
REM Batch Script: find_java_versions.bat | |
REM Description: Searches for all java.exe executables on the host machine and runs each with the -version flag | |
REM to display the Java version information. | |
REM Set the initial search directory to the root of the C drive (you can change this if needed) | |
set "search_dir=C:\" | |
echo Searching for any Java executables ^(java.exe^) in the %search_dir% directory... | |
REM Use the dir command to find all java.exe files on the host machine and store the results in a temporary file | |
dir /s /b "%search_dir%java.exe" > "%temp%\java_exe_list.txt" | |
echo. | |
REM Check if any java.exe files were found | |
if not exist "%temp%\java_exe_list.txt" ( | |
echo No Java executables ^(java.exe^) not found on this machine. | |
) else ( | |
echo Found Java executables: | |
echo. | |
REM Read and run each java.exe from the temporary file | |
for /f "usebackq delims=" %%a in ("%temp%\java_exe_list.txt") do ( | |
echo Running: "%%a" -version | |
"%%a" -version | |
echo. | |
) | |
) | |
REM Clean up the temporary file | |
del "%temp%\java_exe_list.txt" | |
pause |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you find yourself in need of Java to run some small application, this is a way to check if you already have the runtime installed somewhere. Then simply add the directory of any version new enough to run your application to your user path.
Adding a directory to your user path in Windows: