Windows environment variables cannot be parsed correctly

JocuperDARY 20 Reputation points
2023-11-14T02:37:41.17+00:00

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.
9,400 questions
0 comments No comments
{count} votes

Accepted answer
  1. MotoX80 33,296 Reputation points
    2023-11-14T15:09:16.5333333+00:00

    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,876 Reputation points
    2023-11-14T15:28:07.3933333+00:00

    call echo %CLASSPATH% will expand the inner variables

    similarly: call set "Expanded=%CLASSPATH%"

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.