In Windows (e.g. version 10) you can list environment variables using the command


How do you list just the environment variables that are the same for all users or just the environment variables that are for the current user or session?

3 Answers 3


Things are a little more complicated than Microsoft sometimes make it seem.

A lot of the environment variables are stored in the Registry. This means you can query them using the reg command

Common to all users

reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"

Specific to current user session

reg query HKCU\Environment
reg query "HKCU\Volatile Environment"

Set by user

If you permanently set your own environment variable using the setx variable value command it is stored in the registry but not made immediately available.

C:\>setx test removeme

SUCCESS: Specified value was saved.

C:\>reg query "HKCU\Environment"

    Path    REG_EXPAND_SZ    %USERPROFILE%\AppData\Local\Microsoft\WindowsApps;
    TEMP    REG_EXPAND_SZ    %USERPROFILE%\AppData\Local\Temp
    TMP    REG_EXPAND_SZ    %USERPROFILE%\AppData\Local\Temp
    test    REG_SZ    removeme

If you use the set variable=value command, the variable is available immediately but is not stored in the registry. You cannot use the reg command to list them although they are shown by set. These temporary environment variables do not persist after you end the command-prompt session.

Dynamic Environment Variables

There are constructs that act like environment variables that are not stored in the registry in this way. For example:

echo %TIME%
  • 2
    Just a curiosity: is it possible to refresh the variable previously added to registry? e.g. setx test removeme then something set test %test% so that you can have all the variables listed with a simple set? I was thinking that it is possible to implement a command/ batch script to make all them explicit upon request...
    – Hastur
    Commented Feb 16, 2017 at 11:02
  • 1
    @Hastur: Yes, that would work to make a new variable both immediately available and persistent. Commented Feb 16, 2017 at 11:05
  • @hastur @RedGrittyBrick - it is possible but is definitely not an oneliner in windows cmd. If you install chocolatey it has refreshenv.cmd utility which is 10 lines of code and basically it queries and refreshes registry entries
    – maoizm
    Commented Jun 8, 2017 at 11:00
  • Does the SET command show Dynamic Environment Variables? I'm trying to find anything and everything that Microsoft's Build Tools set during a session, just wanna cover my bases.
    – Ungeheuer
    Commented Jul 10, 2017 at 17:00

For clean output without extra lines and black spaces use the following commands in cmd.exe:

User environment variables:

FOR /F "tokens=1,3* skip=2" %G IN ('reg query HKCU\Environment') DO @echo %G=%H %I

Global (system) environment variables:

FOR /F "tokens=1,3* skip=2" %G IN ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"') DO @echo %G=%H %I

It works in Windows 7-10, and most probably in earlier versions as well.

  • 1
    Thanks for this. Note that it drops part of the value if it has spaces in it. So a registry entry like VS140COMNTOOLS REG_SZ C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools shows up as just VS140COMNTOOLS=C:\Program.
    – metal
    Commented Apr 2, 2019 at 17:15
  • @metal thanks for reporting this corner case. Feel free to edit the answer if you find workaround for spaces - I do not have any windows computers now
    – maoizm
    Commented Apr 4, 2019 at 13:54
  • 1
    I have submitted an update to that effect. You or some mod will need to approve it.
    – metal
    Commented Apr 4, 2019 at 14:36

type the batch command: echo %temp%

If the "temp" environment variable contains "H:\Users\amacm\AppData\Local", Windows will immediately respond with the following:


If there is no environment variable named "temp", Windows will respond with the following:



You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .