windows-cmd shell doesn't reflect _winreg changes 
Author Message
 windows-cmd shell doesn't reflect _winreg changes

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?

thanks
hawkeye



Mon, 19 Sep 2005 08:09:21 GMT  
 windows-cmd shell doesn't reflect _winreg changes

Quote:

> 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.



Tue, 20 Sep 2005 02:43:36 GMT  
 windows-cmd shell doesn't reflect _winreg changes
Many thanks Ben!!
Quote:


> > 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.



Mon, 26 Sep 2005 03:08:23 GMT  
 windows-cmd shell doesn't reflect _winreg changes
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.

Quote:

> Many thanks Ben!!



> > > 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.



Sun, 16 Oct 2005 05:52:56 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. _winreg help again -- KEY_SET_VALUE doesn't work!

2. how to pass window title to cmd shell?

3. I changed some tcl but it doesn't change when executing

4. Change directory cmd file - DCD.CMD

5. changing the shell used by 'system'

6. ANN: winreg module (_winreg wrapper)

7. Asynchronous shell doesn't work

8. ulimit doesn't work under a non-root shell

9. Tcl Shell doesn't refer to registry entry when loading

10. twin (Windows Tk port): pack doesn't grow window

11. Changes in superclass are not reflected in subclasses.

12. Refreshing a DropList Queue to reflect a filter change

 

 
Powered by phpBB® Forum Software