Environment variables in Windows 2000

Syver Enstad syver-en at online.no
Tue Nov 20 04:00:45 EST 2001


"Brian Geddes" <brian.j.geddes at intel.com> writes:

> All -
> 
> I've been trying to store/pass information in environment variables in
> Windows 2000, but things aren't working the way I expect them to. 

> The docs
> state that by making changes to the os.system dictionary, 
It's the os.environ dictionary

>the changes should
> be carried over in environment space automatically by os.putenv().  
And it works on my machine (BTW win2k pro) example:

#script1.py

import os
os.environ['DUMMYTEST'] = 'Transfer'
os.system('python script2.py')

----------------------------------------------------------------------
# script2.py

import os
assert os.environ['DUMMYTEST'] = 'Transfer'
print "success"

Running script1.py should print success to stdout (put both files in
the same directory



>However,
> the following which looks like it should work, does not:
No it shouldn't both putenv and assignment just creates entries for
the current environment, this is inherited by process started
by that proces but doesn't affect the environment for the whole OS.

I think you'll have to modify the registry to change environment
variables globally. At least I know that that is one way to acheive
it.

Under 2000 it you assign to the following key make a new system
environment variable:
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session
Manager\Environment]
For a user specific environment variable:
[HKEY_CURRENT_USER\Environment]
(Take a look with regedit yourself to see the layout of it).

Use win32 all to write to the registry, or there maybe support for
writing to the registry in the main distribution now. (Haven't checked
it out).

Hope this helps :-)

-- 

Vennlig hilsen 

Syver Enstad



More information about the Python-list mailing list