System and User Environment Variables has always been a complex topic of discussion for day-to-day Windows OS users. What do they do? A tutorial on the internet said to add a PATH variable, but what is it? Where to do I find these variables? All of these questions will be shortly answered in this post. We’ve tried to give you a high-level overview of what System and User Environment Variables are and how you can utilize them.
In this post, we will discuss Environment Variables, System and User Environment Variables and how to add and modify them. Then we will move on to Dynamic System Variables and see how to use them in the command prompt.
What is an Environment Variable
Environment Variable is formed up by two separate words, ‘Environment’ and ‘Variable’. Let’s discuss ‘variable’ first. It means that the entity can store a value and vary from computer to computer. Windows provide an ‘Environment’ for applications to execute and perform operations and that is what makes the first word. Combining both, Environment Variables are those dynamic objects that store the values provided by the environment. Now environment provides values that help other programs in obtaining some crucial information about the system. Like there is an environment variable called ‘windir’ that corresponds to the directory where Windows is installed. To see this in action, open up an explorer window and type in ‘%windir%’ in the address bar. The Windows installation folder will open up.
Very similarly, you can make reference to the Windows directory using ‘windir’ variable in other programs and scripts. There are numerous other variables that can be accessed, ‘TEMP’ or ‘TMP’ is the variable that points to the directory where all temporary files are stored. The most popular, ‘Path’ variable is the one that points to the directories containing executable files. So that you can run a program from the Command Prompt in any other directory. We’ve explained path later on in this post. All these variables come handy when you are developing something or using the shell a lot.
What are System & User Environment Variables
Very similar to how the registry works on Window, we have System and User Environment Variables. The system variables are system-wide accepted and do not vary from user to user. Whereas, User Environments are configured differently from user to user. You can add your variables under the user so that other users are not affected by them.
Just for your information since we are discussing the topic in depth. System Variables are evaluated before User Variables. So if there are some user variables with the same name as system variables then user variables will be considered. Path variable is generated in a different way. The effective Path will be the User Path variable appended to System Path variable. So the order of entries will be system entries followed by user entries.
How to add & modify Environment Variables
A small warning before we go deeper. Create a system restore point, and try not to tamper with the existing settings configured for your system. Until unless you are very sure about your actions. To open the ‘Environment Variables’ Window, follow these steps:
- Right-click ‘This PC’ icon and select ‘Properties’.
- Now in this window select ‘Advance System Settings’ from the left part.
- Hit the last button saying ‘Environment Variables’ to open our destined window.
Once you’ve opened this up, you will be able to view User and System variables separately. The variable name is in the first column and its value in the second. The corresponding buttons below the table let you ‘Add’, ‘Edit’ and ‘Delete’ these variables.
Using the Path variable
The Path is the most used environment variable. As I mentioned, it points to directories that contain executable files. Once you’ve correctly setup your Path variable, you can use these executables from anywhere in the system. Let’s try to understand this with an example. Open up the environment variables window and look for ‘Path’ in system variables.
Click on ‘Edit’ and then click on ‘New’ without playing around with other controls right now. Now click browse and select a folder which has your desired executable file. Click ‘Ok’ and save everything. I added ‘Visual Studio Code’ executable to the path.
Now to run your application, open up Command Prompt and type in the name of the executable file that was in the folder. You can provide additional arguments if the program supports it. The program will run from the command prompt without actually being in the directory from where you executed the command. That is the beauty of the Path variable.
List of all Environment Variables
Open command prompt and type ‘SET’ and hit Eenter. The entire list of variables with their current values will be displayed and you can refer to it for making changes to your computer.
Dynamic Environment Variables
Unlike, conventional variables, dynamic environment variables are provided by the CMD and not by the system. You cannot change the values of these variables and they expand to various discrete values whenever queried. We usually use these variables for batch processing and these are not stored in the environment. Even the ‘SET’ command will not reveal these variables. Some of the dynamic environment variables are:
Some of the dynamic environment variables are:
- %CD%: Typing in this command will give you the current directory you are working in.
- %DATE%: This variable will give you current date according to date format preferences.
- %TIME%: Similarly, it gives you current time according to the time format preferences.
- %RANDOM%: This variable prints a random number.
- %ERRORLEVEL%: Determines the error level set by last executing command.
- %CMDEXTVERSION%: This variable expands to the version of the command-line extensions.
This was pretty much about System and User Environment Variables on Windows. Windows does come a with a lot more variables – don’t forget to check them using the ‘SET’ command.
TIP: Rapid Environment Editor is a powerful Environment Variables Editor for Windows.