How to modify & Set Windows system environment variables-CMD

Before proceeding further into much detail, let me clear one thing. All the changes to the system environment variables on the cmd – command line are valid only for the current window and are not permanently modified.

That is, when the cmd command line window is closed, it will no longer work. There are two ways to permanently modify environment variables: one is to modify the registry (this method is not currently tested), the other is through My computer -> Properties -> Advanced system setting -> Environment variables, to set the system environment variables. we will discuss both the method here i.e. Direct and CMD method.

What are Windows System Environment variables?

Window Operating system specifies some operating environment or parameters, such as temporary folder location and system folder location. “Path” is a variable which stores some commonly used commands directory path or address. When you run any programs that depend on some regularly used commands these environment variables finds the address of that command and execute the commands easily.  The system variables are set by different programs. Also, if you’re programming in Python environment variables can be used in your programs.

How to check for system environment variables?

When you start the cmd – command line window and call a command. For example, if you type java and press enter then if the system environment has the variable java defined then it will show no error but if the java variable path is not defined then an error is thrown often as “Java is not an internal or external command, operable program or batch file“. This applies to every command.

If your spelling is not wrong and the computer has that program installed, then the error is caused because your path variable is not set up correctly i.e. you have not given the absolute path of your program. That simply means that the operating system do not know where to find your mention program.

How to Set Windows system environment variables

# Direct Method to Set Windows system environment variables

  1. On your Windows PC go to My computer -> right click anywhere and select Properties -> Advanced system setting -> Environment variables.
  2. Here you will see all the system variables defined on your PC.
  3. Now to set the new variable click on New under System variables and give the name of the variable and value is the path of the variable. for ex: “C:jdkbin” is the value for java home.
  4. Like that you can modify the existing variable by clicking on the edit and changing the values.

#  Using CMD to Set Windows system environment variables

To set the variable using CMD, you have to type different codes. I have mentioned all the possible CMD codes to Modify or Add Windows system environment variables by CMD. Check out the full list of codes below. Open CMD first and begin typing the codes mentioned below. The codes are in BOLD letter.

Also read: How to Clean Your Windows Registry and Speed Up Your PC

  1. To view all available environment variables type SET and press Enter.
  2. To see an environment variable value or path: Type set variable name for example, set java will show you the path or value of the path variable.
  3. To modify the environment variable: type set variable name = variable content for example, to set the java path variable value type set path = C:jdkbin or whatever is your address. 
  4. To set an empty value: If you want to set a variable as empty, type set variable name = 
  5. To add variables to the variable: Type set variable name =%variable name%; variable content. For example set path =% path%; c:programfilesprogram.exe to add c:programfilesprogram.exe to path. %path% is the environment variable. 

Below is the list of commonly used environmental variables and their roles to Set Windows system environment variables.

Also read: Merge video clips into one video file using CMD, without any software

  1. % ALLUSERSPROFILE% – Locates the location of all User Profiles locally .
  2. % APPDATA% – Locally Returns the default case where the application data is stored.
  3. % CD%  – Returns the current directory string locally.
  4. % CMDCMDLINE% –  Returns the exact command line used to start the current Cmd.exe.
  5. % CMDEXTVERSION%  – The system returns the current version of the “command handler extension”.
  6. % COMPUTERNAME%  – The system returns the name of the computer.
  7. % COMSPEC%  – The system returns an exact path to the command line interpreter executable .
  8. % DATE%  – The system returns the current date . Use the same format as date / t command. 
  9. % ERRORLEVEL% –  The system returns the error code of the most recently used command. Often a nonzero value is used to indicate an error.
  10. % HOMEDRIVE% –  The system returns the local workstation drive letter that is connected to the user’s home directory. Based on the setting of the home directory value. The user’s home directory is specified in “Local Users and Groups”.
  11. % HOMEPATH%  –  The system returns the full path to the user’s home directory. Based on the setting of the home directory value. The user’s home directory is specified in “Local Users and Groups”.
  12. % HOMESHARE%  –  The system returns the network path of the user’s shared home directory. Based on the setting of the home directory value. The user’s home directory is specified in “Local Users and Groups”.
  13. % LOGONSEVER%  –  Local Returns the name of the domain controller that validates the current logon session.
  14. % NUMBER_OF_PROCESSORS%  –  The system specifies the number of processors installed on the computer.
  15. % OS%  –  The system returns the name of the operating system. Windows 2000 displays the operating system as Windows_NT.
  16. % PATH% –   The system specifies the search path for the executable file .
  17. % PATHEXT%  –  The system returns a list of file extensions that the operating system considers executable.
  18. % PROCESSOR_ARCHITECTURE%  –  The system returns the processor’s chip architecture.
  19. % PROCESSOR_IDENTFIER%  –  The system returns the processor description.
  20. % PROCESSOR_LEVEL%  –  The system returns the model of the processor installed on the computer.
  21. % PROCESSOR_REVISION% –   The system returns the system variable for the processor revision number.
  22. % PROMPT%  –  Returns the command prompt for the current interpreter . Generated by Cmd.exe.
  23. % RANDOM%  –  The system returns any decimal number between 0 and 32767 . Generated by Cmd.exe.
  24. % SYSTEMDRIVE%  – The system returns a drive that contains the root directory of Windows(that is, the system root).
  25. % SYSTEMROOT% –  The system returns the location of the Windows root directory.
  26. % TEMP% and % TMP%  –  The system and user return the default temporary directory used by the application that is currently available to the logged-on user. Some applications require TEMP, while other applications require TMP.
  27. % TIME%  – The system returns the current time. Use the same format as time /t command. Generated by Cmd.exe.
  28. % USERDOMAIN%  –  Returns the name of the domain containing the user account locally.
  29. % USERNAME%  –  Returns the name of the user who is currently logged in.
  30. % UserProfile% –  Locates the location of the current user’s profile locally.
  31. % WINDIR% –  The system returns the location of the operating system directory.

That’s all n this post. So now you know how to Set Windows system environment variables directly or by using CMD.

Leave a Comment

Exit mobile version