Reading Windows (NT/2000/XP) system and user environment variables

J

Jim Potts

What is the best way in Python version 2.x to read/get Windows (nt/2000/xp)
system and user environment variables?

Thanks for the help!

jep
 
G

Gerrit Holl

What is the best way in Python version 2.x to read/get Windows (nt/2000/xp)
system and user environment variables?
</quote>

import os
os.environ

See also the documention on the os module.

Gerrit.
 
R

Rudy Schockaert

Jim said:
What is the best way in Python version 2.x to read/get Windows (nt/2000/xp)
system and user environment variables?

Thanks for the help!

jep
first install Mark Hammond's excellent Win32all extensions:
http://starship.python.net/crew/mhammond/

Then it's really simple:'c:\\bin;c:\\Python23\\scripts;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\PROGRA~1\\COMMON~1\\Ulead
Systems\\MPEG;C:\\Program Files\\Common Files\\Ulead Systems\\MPEG'
 
F

Felix McAllister

If you need to get the list of system environment variables and the (separate) list of user environment variables, you'll have to read the following registry settings:

System: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

User: HKEY_CURRENT_USER\Environment

You can use the win32api functions RegConnectRegistry, RegOpenKey, RegQueryValue etc. for these.

Felix.
 

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

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,440
Latest member
YoungBorel

Latest Threads

Top