Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

VS140COMNTOOLS also doesn’t appear in set output.

How can I navigate into %VS140COMNTOOLS%?

>Solution :

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.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading