Environment variables

Kevin Cazabon kcazabon at home.com
Sat Dec 4 00:56:07 EST 1999


Hmmm... I haven't had that experience, here's what happens to me on NT:

##################
newpath = os.environ["PATH"] + ";c:\\Program Files\\Tcl\\bin"
pathkey = RegOpenKey(win32con.HKEY_LOCAL_MACHINE, \
    "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment\\", \
    0, win32con.KEY_SET_VALUE)

RegSetValueEx(pathkey, "Path", 0, win32con.REG_SZ, newpath)
RegFlushKey(pathkey)
RegCloseKey(pathkey)
##################

This is supposed to add "c:\Program Files\Tcl\bin" to the NT PATH (so that
Tcl will work, for example).  However,  if I then immediately exit Python,
and start a new Python program that requies Tcl/Tk, I get an error saying
that one of the required DLL's is not in the system path (and it
conveniently lists the current PATH, which does NOT have my addition in it).

Then, if I then go to the Control Panel/System/Environment tab, my addition
IS there...  If I then say "OK", and try the program again, everything
WORKS.  But, until I go into the Control panel, or reboot, it does NOT work.
So, to me it looks like it's just not effective until I force NT to
re-initialize the path.

Does that make sense?  Is there an easier way to make it effective
immediately (the "flush" doesn't seem to do anything).  I use the
os.putenv(), but it's no good for a separate Python thread. (Hey Mark, if
you're out there...)  q:]

Oh well...

Kevin Cazabon
kcazabon at home.com


"Gordon McMillan" <gmcm at hypernet.com> wrote in message
news:1267895477-5653035 at hypernet.com...
> Kevin Cazabon on making changes to environment vars:
>
> > I ran into the same thing...  It's not too hard on NT, as you can
> > set most of them through the registry using Mark Hammonds Win32
> > Extensions.  For Win98, I've been adding the changes to the
> > autoexec.bat and forcing a reboot.
> >
> > One thing I've found though:  changing things in the NT registry
> > works, but the changes don't actually become effective
> > immediately.  I'd recommend a reboot to be safe after setting up
> > your changes.
>
> Actually, they do. Just not in already running cmd.exes. You
> can use os.putenv to affect the environment of the cmd.exe
> you're running in, but there's nothing you can do about other
> already existing ones.
>
>
>
> - Gordon
>
>






More information about the Python-list mailing list