开发者

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
  • Environment variables are more common across platforms (?).

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜