Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Can someone show me how to write a VBScript that finds the directory of the latest Java Development Kit, using the following algorithm.
Search the Registry for the following key:
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit
find the value "CurrentVersion", and then append that value (e.g. "1.6") to the above key and look up the new key, e.g.
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\1.6
then look in there for the value of "JavaHome" and print it to stdout.
If at any time it doesn't find any of the above, just terminate (preferably with a non-zero exit code) without printing anything.
Thanks in advance. (I need this because I've written a batch file that compiles Java source files, and I'm going to give this to people who possibly may not have added javac.exe in the PATH.)

It's all right lads, no need for VBScript, I did it all using batch and reg.exe:
@echo off
for %%j in ("HKLM\SOFTWARE\JavaSoft\Java Development Kit") do (
for /f "tokens=2*" %%a in ('reg query %%j /v CurrentVersion 2^>nul') do if %%a==REG_SZ (
for /f "tokens=2*" %%c in ('reg query "%%~j\%%b" /v JavaHome 2^>nul') do if %%c==REG_SZ (
echo %%d
)
)
)

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |