Retrieving a registry variable in a batch script

1

1

I wish to write a batch script (windows XP) that extracts certain installation paths from the registry.

How would one go about writing such a script?

I have written the following - I am (as you might see from my example below) a programmer, but know virtually nothing about batch scripts. comments to the below are also appreciated:

@echo off

set Count=0
for %%a in (%*) do set /a Count+=1

if %Count% GEQ 3 goto :error
if %Count% EQU 1 goto :SET_FOUND_JAVA
if %Count% EQU 2 goto :SET_FOUND_NSIS
if %Count% EQU 0 goto :MUST_CALULATE

:SET_FOUND_JAVA
set tmp_java=%1
goto :FOUND_JAVA

:SET_FOUND_NSIS
set tmp_java=%1
set tmp_nsis=%2
goto :FOUND_NSIS

:MUST_CALULATE
For /F "tokens=*" %%I in ('REG QUERY "HKLM\SOFTWARE\JavaSoft\Java Development Kit\1.6" /v JavaHome') Do Call :PARSE_JAVA %%I
GoTo :CALCULATED_JAVA
:PARSE_JAVA
If "%1"=="" GoTo :EOF
set java_location=%1
Shift
GoTo :PARSE_JAVA

:FOUND_JAVA
set java_location=%tmp_java%

:CALCULATED_JAVA
set JAVA_HOME=%java_location%

For /F "tokens=4* skip=2" %%I in ('REG QUERY HKLM\SOFTWARE\NSIS /ve') Do Call :PARSE_NSIS %%I
GoTo :CALCULATED_NSIS
:PARSE_NSIS
If "%1"=="" GoTo :EOF
set nsis_location=%1
Shift
GoTo :PARSE_NSIS

:FOUND_NSIS
set java_location=%tmp_java%
set nsis_location=%tmp_nsis%
:CALCULATED_NSIS
set JAVA_HOME=%java_location%
set NSIS_DIR=%nsis_location%


Echo JAVA Home found at %JAVA_HOME%
Echo NSIS Home found at %NSIS_DIR%



mvn -P package -Dnsis.dir=%NSIS_DIR% clean package

go end

:error
echo USAGE %0
echo USAGE %0 [JAVA_HOME]
echo USAGE %0 [JAVA_HOME] [NSIS_HOME]
:end

EDIT 1:

Running it on my computer produces the following:

JAVA Home found at P:\Java\jdk1.6.0_20
NSIS Home found at P:\NSIS

Whereas running it on another computer produces:

JAVA Home found at Files\Java\jdk1.6.0_18
NSIS Home found at

This is since the command:

REG QUERY "HKLM\SOFTWARE\JavaSoft\Java Development Kit\1.6" /v JavaHome

Produces:

! REG.EXE VERSION 3.0

HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\1.6
    JavaHome    REG_SZ  C:\Program Files\Java\jdk1.6.0_18

Yaneeve

Posted 2010-07-08T10:42:42.987

Reputation: 165

The above code works only when the installation paths have no spaces within them – Yaneeve – 2010-07-08T10:43:55.590

You seem to have answered your own question. Does your code not work? What does it do? Can you perhaps ask your question in a different way? – boot13 – 2010-07-08T14:10:20.993

@boot13 - please look at the added edit – Yaneeve – 2010-07-08T14:19:46.503

No answers