1

I am looking for a way of retrieving the "Windows System Environment Variables", as shown in the GUI dialog :

Control Panel -> System Properties -> Advanced Tab -> Environment Variables

from the command line, on Windows 10 for x86_64, Build 19042.746, Version 20H2 , fully up-to-date as of 2021/01/20.

Retrieving the persistent User environment variables is no problem, with a command like:

 C:\>REG QUERY HKCU\Environment /v Path HKEY_CURRENT_USER\Environment
 Path    REG_EXPAND_SZ    %USERPROFILE%\AppData\Local\Microsoft...

But there appears to be no registry entry containing the "System Variables". I have searched in RegEdit for any value containing a string in my System $Path, with no success.

Rumors have it on the web that the System Environment variables are meant to be stored on in the Registry at:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

But there is no such key in my Registry - from a System Administrator 'CMD.EXE' prompt, I try the following with no success:

C:\>REG QUERY 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session -\  
              Manager\Environment' /v 'Path'
ERROR: Invalid key name.
Type "REG QUERY /?" for usage.

C:\>REG QUERY 'HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\ -\   
              Environment' /v 'Path'
ERROR: Invalid key name.
Type "REG QUERY /?" for usage.

C:\>REG QUERY 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment' -\ 
              /v 'Path'
ERROR: Invalid key name.
Type "REG QUERY /?" for usage.

If anyone might know what key the system path is stored under, please post it here.

I have read all the Microsoft Registry and 'REG.EXE' reference documentation with no light being shed on this matter at all.

All the names on the web for the system environment variable key name seem to be out of date.

Would anyone know what it is ?

Or perhaps how to convert the Registry into an ASCII or UTF-8 text file so that I could search for strings in it? ( 'REGEDIT -e output_file' does not work - it produces a 96MB
binary file 'output_file' in some format that does not allow text searching. ).

Thanks in advance for any replies!

1
  • 1
    OK, after converting the binary output of 'regedit -e' to UTF-8, I was able to view the Registry Contents, and found the key: HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment\ But is this under 'ControlSet001' , not ControlSet. How can one determine what the value of the suffix of the ControlSet ('001' in this case) should be ? Will ControlSet001 always exist and contain the PATH setting? Commented Jan 22, 2021 at 15:14

1 Answer 1

1

Simple , use " and not ' for quoting space.

REG QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /s

That is to have all environment vars with a particular path.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.