How to Manage Environment Variables in Windows
An environment variable is a dynamic value that the operating system and other software can use to determine information specific to your computer.
In other words, an environment variable is something that represents something else, like a location on your computer, a version number, a list of objects, etc.
Open Command Prompt and type SET and press Enter key. The entire list of variables with their current values will be displayed and you can refer to it for making changes to your computer.
Environment variables are surrounded by the percent sign (%), as in %temp%, to distinguish them from regular text.
Two types of environment variables exist, user environment variables and system 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.
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:
1. Press Windows + R Keys to open Run box.
2. Type sysdm.cpl ,3 into Run box and click OK button.
3. From System Properties window click Environment Variables button.
The Environment Variables window is opened. On the top, it displays your user’s variables, and on the bottom, it shows the system variables, valid for all user accounts existing in Windows.
Once you’ve opened Environment Variables window, 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.
The Path is the most used environment variable. It points to directories that contain executable files. So that you can run a program from the Command Prompt in any other directory.
Open up the environment variables window and select Path in system variables.
Click on Edit button and then click on New button. Now click Browse button and select a folder which has your desired executable file. Click OK and save everything.
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.
Set environment variables permanently using SETX command which can be used to set Environment Variables for the machine or currently logged on user.
Because SETX command writes variables to the master environment in the registry, edits will only take effect when a new command window is opened - they do not affect the current Command Prompt or PowerShell session.
If variables with the same name are stored as both User and Machine Environment variables, the user variable will take precedence.
Open the Command Prompt by clicking Start Menu --> All Programs --> Accessories, right-click on Command Prompt, and open it as an administrator. In Windows Vista and later versions of Window operating systems type cmd.exe into Start Screen or Start Menu, right-click on Cmd.exe, and open it as an administrator.
Set the variable _car_park to be 'South' in the users environment:
Set the variable _car_park to be 'North' in the MACHINE environment:
For more information about Setx command execute following command:
Environment variables are stored in the registry:
User Variables: HKEY_CURRENT_USER\Environment
System Variables: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
The User Variables you have set using SETX command can either deleted from Environment Variables window or using Registry Editor.
The System Variables you have set using SETX command can either deleted from Environment Variables window or using Registry Editor.
In other words, an environment variable is something that represents something else, like a location on your computer, a version number, a list of objects, etc.
Open Command Prompt and type SET and press Enter key. The entire list of variables with their current values will be displayed and you can refer to it for making changes to your computer.
Environment variables are surrounded by the percent sign (%), as in %temp%, to distinguish them from regular text.
Two types of environment variables exist, user environment variables and system 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.
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:
1. Press Windows + R Keys to open Run box.
2. Type sysdm.cpl ,3 into Run box and click OK button.
3. From System Properties window click Environment Variables button.
The Environment Variables window is opened. On the top, it displays your user’s variables, and on the bottom, it shows the system variables, valid for all user accounts existing in Windows.
Once you’ve opened Environment Variables window, 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.
The Path is the most used environment variable. It points to directories that contain executable files. So that you can run a program from the Command Prompt in any other directory.
Open up the environment variables window and select Path in system variables.
Click on Edit button and then click on New button. Now click Browse button and select a folder which has your desired executable file. Click OK and save everything.
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.
Set environment variables permanently using SETX command which can be used to set Environment Variables for the machine or currently logged on user.
Because SETX command writes variables to the master environment in the registry, edits will only take effect when a new command window is opened - they do not affect the current Command Prompt or PowerShell session.
If variables with the same name are stored as both User and Machine Environment variables, the user variable will take precedence.
Open the Command Prompt by clicking Start Menu --> All Programs --> Accessories, right-click on Command Prompt, and open it as an administrator. In Windows Vista and later versions of Window operating systems type cmd.exe into Start Screen or Start Menu, right-click on Cmd.exe, and open it as an administrator.
Set the variable _car_park to be 'South' in the users environment:
Set the variable _car_park to be 'North' in the MACHINE environment:
For more information about Setx command execute following command:
Code:
Setx /?
Environment variables are stored in the registry:
User Variables: HKEY_CURRENT_USER\Environment
System Variables: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
The User Variables you have set using SETX command can either deleted from Environment Variables window or using Registry Editor.
The System Variables you have set using SETX command can either deleted from Environment Variables window or using Registry Editor.