Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Registry Variables vs. Environment Variables?

At first glance this seems like a purely subjective/aesthetic issue, but I'd be interested to hear opinions (especially any technical ones) on whether environment variables or the registry is the preferred place for storing configuration data in a Windows environment.

I can currently only think of the following differences:

  • Registry settings are persistent across sessions, though I believe that environment variables can also have this property.
  • It's easier to set environment variables from the command-line vs. using regedit
    • (Counter-argument: regedit easier for non-command-line apps?)
  • Environment variables are more common across platforms (?).

I'm also aware that environment variables can be interrogated, modified and set from the registry.

like image 866
kfb Avatar asked Jan 08 '10 16:01

kfb


People also ask

What is the difference between variables and environment variables?

The difference between the two is that variables values may change during execution, while constant values cannot be reassigned. An environment variable is a variable whose value is set outside the program, typically through functionality built into the operating system or microservice.

Where in registry is the environment variables?

Machine environment variables are stored or retrieved from the following registry location: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment . Process environment variables are generated dynamically every time a user logs in to the device and are restricted to a single process.

What can I use instead of environment variables?

Instead of environment variables, we recommend that you either use a YAML configuration file or a shared data source.


1 Answers

Use environment variables when you intend to be configured by other applications (or by a technical user) and that this configuration could be different (i.e. you have 2 instances running at the same time, with different settings). Cluttering a user's environment isn't usually necessary. In most cases, use the registry, or a config file stored in $HOME\AppData\Roaming\YourApp.

like image 93
Ana Betts Avatar answered Oct 08 '22 07:10

Ana Betts