Home > Enterprise >  System variables aren't evaluated in Windows command prompt, user variables are
System variables aren't evaluated in Windows command prompt, user variables are

Time:05-04

I would like to be able to cd into a folder that is added to a system as a system variable in Windows 11. Here is a visual representation of the problem:enter image description here

As you can see, windows command prompt is able to "resolve" variables from the "User variables" section of the Environment variables configuration in Windows, however variables from the "System variables" aren't.

I need to cd into %VS140COMNTOOLS% folder but as you can see it won't be resolved by the command prompt. Is this by design?

VS140COMNTOOLS also doesn't appear in set output.

How can I navigate into %VS140COMNTOOLS%?

CodePudding user response:

System variables and user vars end up in a single environment block. When expanding env vars, there's no concept of user/system. User vars override system vars.

Also: each process gets its own copy of env vars which is resolved when the process launches. Therefore, if a process appears to be "missing" an env var, one of the following happened:

  1. The variable was set after the process launched. For example maybe this command prompt was open during the installation of something that created an env var. You'll need to re-launch the command prompt to get the var.
  2. OR, the process modified it / removed it.
  • Related