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.
Help
More information about set command ca be printed with /?
option.
$ set /?

Syntax
Syntax of the set command is very simple. [variable]
and [string]
parts are optional and used according to situation
SET [variable=[string]]
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.
$ set

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 1
$ 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
Get Username
The currently logged users user name can be printed like below.
$ set USERNAME
You don’t show how to actually USE an environment variable.
For example, suppose I SET DIR = Dov.
How do I USE DIR to change directory to C:\Users\Dov?
How about cd C:\users\%DIR%? Seems reasonable. But it’s wrong.
Do you want to add how to USE environment variables?
Oh, and what about those “$” characters before, for example, SET. Illegal syntax?
Oh… is “$” the command line PROMPT? Why is it not on ALL command examples?
If I’m being dense, I apologize.