1
setlocal enabledelayedexpansion
FOR /F "skip=2 tokens=2*" %%A IN ('REG QUERY "HKLM\Software\JavaSoft\Java Development Kit\1.6" /v JavaHome') DO set JavaPath=%%B
SETX -m JAVA_HOME "%JavaPath%"
ECHO java__path variable: !JavaPath!
ECHO java__path: %JAVA_HOME%
  • Am setting java home from registry.
  • the values is getting set.
  • SETX is working.

when i try echo using !JavaPath!, am getting value and when i tried echo %JAVA_HOME%, the value is empty.

I tried with enabledelayedexpansion also but no use. How to echo %JAVA_HOME%??

2 Answers 2

0

Follow the setx with another set to reset the local variable.

SETX -m JAVA_HOME "%JavaPath%"
SET "JAVA_HOME=%JavaPath%"

If these are all within another loop then use !variable! syntax.

0

You appear to be setting JavaPath from the value of JavaHome (no underscore) in the registry.

SETX AFAIAA WRITES the value into the registry but does not assign the value to the variable.

The value in JAVA_HOME in the registry would be available to FUTURE sessions, but not already-established sessions.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.