0

My PATH has few entries like %SystemRoot%, %USERPROFILE%/... etc which are pointing to another env variable. But when I update the PATH with command line, it replaces those env entries with actual value like e.g. below

Earlier Entry : %SystemRoot%;%USERPROFILE%\AppData

SETX MY_ENV "C:\MyData"
SETX PATH %MY_ENV%;%PATH%

Path Value : C:\MyData;C:\Windows;C:\USers\UserName\AppData

But, I am looking for a solution which can be run directly as cmd line por through Batch programming that will set my Path as below

%MY_ENV%;%%SystemRoot%;%USERPROFILE%\AppData

This is not the Path variable meant for logged in user but is the system path variable.

mael'
  • 453
  • 3
  • 7
ImLearning
  • 21
  • 4
  • 2
    Do not use `setx` for modifying the `PATH` variable! The value of `%PATH%` you see is a mixture of a user-defined and a system-level `PATH` variable definition in the Registry; `setx` messes around with them! – aschipfl Jul 25 '19 at 13:11
  • It's not messing the content there but it expands the env variables used in Path to the actual location. Is there a workaround for this? – ImLearning Jul 25 '19 at 13:17
  • 2
    Well, `%PATH%` returns a combination of user- and system-level PATH settings, so `setx PATH %MY_ENV%;%PATH%` writes the result to the user-defined PATH setting in the registry, that is what I meant by "messing around". I guess it is smarter to modify the registry settings directly... – aschipfl Jul 25 '19 at 14:12

0 Answers0