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

C

could ildg

To a environment variable in Windows, can python know if it is a
system environment
variable or a current-user environment variable?
 
P

Peter Hansen

could said:
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
 
K

Kartic

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,234
Messages
2,571,178
Members
47,808
Latest member
sunnysingh55

Latest Threads

Top