env variable set using _winreg.SetValueEx() doesn't show w/ os.environ
Erick Bodine
erick_bodine at comcast.net
Tue Dec 16 15:59:30 EST 2003
I am trying to set a new environment variable on a W2k machine with
only partial success. The name("SSID") and value("ASIM") show up
correctly in the registry and when I go to "System
Properties"->Advanced->"Environment Variables". However, if I open a
console and type 'set', "SSID" is not listed; also if I open a python
shell and do os.environ["SSID"] the variable is not found. What am I
doing wrong???
import _winreg
system = r"SYSTEM\CurrentControlSet\Control\Session
Manager\Environment"
registry = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)
env_key = _winreg.OpenKey(registry, system, 0, _winreg.KEY_SET_VALUE)
key = "SSID"
value = "ASIM"
try:
_winreg.SetValueEx(env_key, key, 0, _winreg.REG_EXPAND_SZ, value)
except EnvironmentError:
print "Encountered problems writing (%s) into the registry" % key
_winreg.CloseKey(env_key)
_winreg.CloseKey(registry)
I have tried this using ActivePython-2.3.2-232 and Python-2.3.2 w/ the
same results.
Thanks,
ERick
More information about the Python-list
mailing list