windows-cmd shell doesn't reflect _winreg changes
Author |
Message |
haugh #1 / 4
|
 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 |
|
 |
Ben Hutching #2 / 4
|
 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 |
|
 |
haugh #3 / 4
|
 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 |
|
 |
haugh #4 / 4
|
 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 |
|
|
|