How To List, Set, Get Windows Environment Variables With Set Command In Command Line MS-DOS?
Operating systems have a lot of configurations. These configurations are stored in different ways in different locations. One of the most common storage for some generic information like Username, operating system path etc. is environment variables. In this tutorial we will look how to list, get and set Windows operating system environment variables in details. We will use
set command mainly. Set command lists, sets and gets single or all environment variables.
More information about set command ca be printed with
$ set /?
Syntax of the set command is very simple.
[string] parts are optional and used according to situation
List All Environment Variables
Environment variables holds a lot of information about the operating system and user . All these information can be listed just issuing the
set command without any parameter like below.
Get/Print Single Environment Variable
In previous example we have listed all environment variables without selecting particular one. We can print only single variable just proving the variable name to the set command. In this example we will print the values of
APPDATA environment variable.
$ set APPDATA
Change/Create Environment Variable
Now the last function of the set command. We can create or change and environment variable and its value by giving both the variable name and the variable data. In this example we create a new variable named
Test with value
$ set Test=1
Get Home Path
Home is the current users location where his personal files and folders stored. This path can be printed like below.
$ set HOMEPATH
Get Logon Server
Logon server is used to authenticate the user to login a system. In active directory system user credentials are authenticated in these authority servers.
$ set LOGONSERVER
Get Path Variable
Path variable is used to find executable files. Path variable stored more than one path and if a command is issued these path are checked for this command executables to run.
$ set PATH
Get Program Files Path
Windows operating system stores built-in and 3 party applications files and folder in
Program Files directory. This directory path can be printed like below.
$ set ProgramFiles
Get System Root
Windows operating system files, folders and libraries are stored in
System Root and this root directory generally named
windows . By default this path is
C:\Windows . The system root can be printed like below.
$ set SystemRoot
The currently logged users user name can be printed like below.
$ set USERNAME