0

Windows provide us with a Graphical User Interface (GUI) where we may supposedly see the environment variables available, which may be accessed at Config App > System > About > Advanced system settings.> Environment Variables. There we may see System and User environment variables.

Currently it show may the following user variables:

  • Path
  • TEMP
  • TMP
  • PATHEXT
  • OneDrive

And the system variables bellow:

  • ComSpec
  • DriverData
  • OS
  • Path
  • PATHEXT
  • PROCESSOR_ARCHITECTURE
  • PSModulePath
  • TEMP
  • TMP
  • USERNAME
  • windir
  • NUMBER_OF_PROCESSORS
  • PROCESSOR_LEVEL
  • PROCESSOR_IDENTIFIER
  • PROCESSOR_REVISION

Considering that an instance of CMD would receive a copy of the environment block of its parent process — which I suppose is initially Windows itself — I expected it to have an exact copy of those variables, and nothing more. However, when I run SET command a lot more environment variables and not just the ones listed above.

The "extra" variables displayed:

  • ALLUSERSPROFILE
  • APPDATA
  • CommonProgramFiles
  • CommonProgramFiles(x86)
  • CommonProgramW6432
  • COMPUTERNAME
  • FPS_BROWSER_APP_PROFILE_STRING
  • FPS_BROWSER_USER_PROFILE_STRING
  • HOMEDRIVE
  • HOMEPATH
  • LOCALAPPDATA
  • LOGONSERVER
  • ProgramData
  • ProgramFiles
  • ProgramFiles(x86)
  • ProgramW6432
  • PROMPT
  • PUBLIC
  • SESSIONNAME
  • SystemDrive
  • SystemRoot
  • USERDOMAIN
  • USERDOMAIN_ROAMINGPROFILE
  • USERPROFILE

Why SET command shows more variables than GUI does? Where comes the other environment variables listed by SET?

Fb16455
  • 101
  • 1
  • 7
  • 1
    There aren't just the System `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment` and User `HKEY_CURRENT_USER\Environment` environments, there is also a Volatile `HKEY_CURRENT_USER\Volatile Environment` environment too. Other 'True' variables are parsed/generated from ntdll.dll. – Compo Jul 16 '22 at 06:00
  • 1
    I recommend to read the second chapter __Windows shell variables__ in my answer on [Difference between Dynamic Environment Variables and Normal Environment Variables in CMD](https://stackoverflow.com/a/65979943/3074564) to get knowledge of the environment variables defined by the Windows shell (`explorer.exe`). – Mofi Jul 16 '22 at 07:28

1 Answers1

0

When you log in, winlogon.exe (GINA in older NT) loads the users profile and initializes the base environment, and then starts userinit.exe and before userinit starts Explorer it runs logon scripts and updates the environment. USERNAME and COMPUTERNAME are of course user and machine specific. Things like APPDATA come from the users shell folder paths.

Anders
  • 97,548
  • 12
  • 110
  • 164