Pcornel
Windows · Windows Fundamentals

Environment Variables

Cheat sheet · https://pcornel.dk/topic.php?topic=2933

Back to the Topic

Answer

Environment variables are name/value pairs exposed through a process environment block. Windows commonly distinguishes Process, User and Machine scopes. A new process normally inherits a copy of its parent’s environment, while persistent User/Machine values seed future process environments.

Remember

  • A process owns its current environment block. Changing a persistent variable does not rewrite every existing process.
  • User and Machine variables persist; Process-scope changes disappear with that process unless explicitly persisted elsewhere.
  • Child processes normally inherit a copy of the parent environment at creation time.
  • %NAME% is common cmd expansion; PowerShell uses $env:NAME for process-environment access.
  • Machine/User persistent environment settings are backed by Registry locations, but applications consume process state.

First checks

  • Get-ChildItem Env: — environment of the current process
  • [Environment]::GetEnvironmentVariable('<Name>','Machine') — machine-level value
  • [Environment]::GetEnvironmentVariable('<Name>','User') — user-level value
  • setx <Name> <Value> — persist for the user (new processes)

Verify in this order

machine and user variables → merged at logon/process start → inherited by child processes → read by the program

Where it usually breaks

First mismatch in target identity/version → persistent configuration/source of truth → provider/service/control plane → runtime/effective state → user/workload-visible result → event/log evidence; preserve identity/native error/pre-state before mutation.

Environment-variable scopes

ScopeLifetime / persistenceTypical verification
Processcurrent process lifetimeread from the exact shell/process
Userpersistent for one user; seeds future processescompare User config with a newly started process
Machinepersistent system-wide; seeds future processescompare Machine config with newly started user/service processes
Child processinherits a copy from parent unless overriddenidentify parent and creation time

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=2933

Confirmation

Confirm action

Continue?