By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,516 Members | 1,831 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,516 IT Pros & Developers. It's quick & easy.

Is it possible to distinguish between system environment variablesand the user ones?

P: n/a
To a environment variable in Windows, can python know if it is a
system environment
variable or a current-user environment variable?
--
鹦鹉聪明绝顶、搞笑之极,是人类的好朋友。
直到有一天,我才发觉,我是鹦鹉。
我是*墙的鹦鹉。
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
could ildg wrote:
To a environment variable in Windows, can python know if it is a
system environment
variable or a current-user environment variable?


Not just by using the "os.environ" approach.
You would have to resort to the "pywin32"
extensions. Check the Python Cookbook using
Google for "environment variable" recipes and
you'll get a good start on it.

You'll also require a bit of Win32-specific
knowledge, since this entire concept is not
a cross-platform one.

-Peter
Jul 18 '05 #2

P: n/a
There is nothing that plainly differentiates whether an environment
variable is the system's or the current user's.

What you could do is:
1. Get the list of environment variables for the user the script is
executing as.
2. Use the pywin32 extensions to access the registry key
HKCU\Environment
3. Lookup the environment variables present in the list (Item 1) that
appear as string values under HKCU\Environment.
4. The intersecting list belongs to the user, the rest can be surmised
as belonging to the system environment.

Thanks,
--Kartic

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.