windows-cmd shell doesn't reflect _winreg changes

haughki hawkeye.parker at autodesk.com
Tue Apr 29 17:52:56 EDT 2003


follow up:

the SendMessage command as suggested below didn't actually work.  I
did some poking around on the win32 newsgroup and eventually found MS
Knowledge Base's Q104011, "HOWTO: Propagate Environment Variables to
the System".  it suggests:

SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)
"Environment", SMTO_ABORTIFHUNG, 5000, &dwReturnValue);

which is pythonified to:

win32gui.SendMessageTimeout(win32con.HWND_BROADCAST,
win32con.WM_SETTINGCHANGE, 0, "Environment",
win32con.SMTO_ABORTIFHUNG, 5000)

and actually works.  you still have to close the cmd shell and reopen
it, but this is much faster than going through the whole process
manually.


hawkeye.parker at autodesk.com (haughki) wrote in message news:<b6e56f7a.0304091108.6030e453 at posting.google.com>...
> Many thanks Ben!!
> 
> 
> 
> 
> Ben Hutchings <do-not-spam-ben.hutchings at businesswebsoftware.com> wrote in message news:<slrnb8p06l.174.do-not-spam-ben.hutchings at tin.bwsint.com>...
> > In article <b6e56f7a.0304021609.521700e6 at posting.google.com>, haughki wrote:
> > > hi
> > > 
> > > i'm using _winreg to 'hard-change' and environmental variable in
> > > windows.  the change is 'successful': regedit correctly reflects the
> > > changes, and crtl panel > system > properties envronmental vars have
> > > been correctly changed.  but, when i start a cmd shell (dos), the
> > > shell evironment still reflects the old values until i manually open
> > > the env vars cntrl panel and click 'ok'.  anyone?
> > 
> > This is really a Win32 programming issue rather than a Python one.
> > However, I do vaguely remember this one.
> > 
> > Environmental variables are normally passed to a new process by the
> > process that creates it, and they can never be updated from outside
> > a process.  The exception to this is that Windows Explorer (and any
> > other program that wishes to) will read those initial environment
> > variables out of the registry when notified of a change in settings.
> > The changes will then be passed on to any program started by Explorer
> > afterwards.
> > 
> > Here's the Python code:
> > 
> >     import win32con, win32gui
> >     win32gui.SendMessage(
> >         win32con.HWND_BROADCAST, win32con.WM_SETTINGCHANGE, 0, 0)
> > 
> > You might want to use SendMessageTimeout instead of SendMessage.




More information about the Python-list mailing list