views:

294

answers:

2

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.

+1  A: 

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.

Paul Betts
A: 

When using windows services, environment variables can be a pain: Just changing the variable and then restarting the service will not help. Usually the system needs to be restarted.
If the service looks up settings in the registry, this is much easier.

I saw this behavior on Windows XP, I'm not sure if the later versions have resolved this issue.

mxp