Search code examples
environment-variablesregistrywindows-console

Windows: User environment variable cannot be displayed with echo


I am looking at a user environment variable created using Windows console command

reg add "hkcu\environment" /v SARMaster_Server_Name /d %smServer%

This variable name SARMaster_Server_Name can be seen in the registry under HKCU/Environment with the correct value as well as through the advanced System settings of the Control Panel.

However, when I run

echo %SARMaster_Server_Name%

I get %SARMaster_Server_Name% instead of the actual value of this environment variable. What did I miss? All other environment variables such as TEMP can be echoed.


Solution

  • Variable is being set correctly using

    reg add "hkcu\environment" /v SARMaster_Server_Name /d %smServer%
    

    However, I need to restart to be able to access this variable. A workaround, which does not help in my scenario is to open the Environment Variables editor from the Control Panel and click on OK after the variable has been added using "reg add". Somehow, this action registers the new variable which can now be accessed on a new CMD session. Problem is being reported on XP so it may have been fixed on Windows 7 a