Windows environment variables cannot be parsed correctly

JocuperDARY 20 Reputation points

Using a command such as "echo %CLASSPATH%" in the cmd window returns ".;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.;" instead of ".;C:\Program Files\Java\jdk-17.0.5\lib\dt.jar;C:\Program Files\Java\jdk-17.0.5\lib\tools.jar;" However, if you use the command "echo %JAVA_HOME%", it returns "C:\Program Files\Java\jdk-17" Some of these environment variables can be parsed, while in some situations they cannot be parsed, which bothers me, hoping to receive a suitable solution. Version: Windows11 professional workstation 23H2 22635.2700 Windows Feature Experience Pack 1000.22678.1000.0

Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
6,795 questions
0 comments No comments
{count} votes

Accepted answer
  1. MotoX80 29,371 Reputation points

    The registry entries for the variables should be REG_EXPAND_SZ and not REG_SZ.

    System: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

    User: HKEY_CURRENT_USER\Environment

    You may have to delete and recreate the variable. If it's a system variable, a reboot will probably be needed to pick up the change.

    User's image

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. abbodi86 3,356 Reputation points

    call echo %CLASSPATH% will expand the inner variables

    similarly: call set "Expanded=%CLASSPATH%"

    1 person found this answer helpful.
    0 comments No comments