[New-bugs-announce] [issue30374] Make win_add2path.py take effect without having to log off
report at bugs.python.org
Mon May 15 13:48:25 EDT 2017
New submission from neeverett:
I was trying to add Python to Windows PATH and found this tool. But after I ran it and restarted the Command Prompt, nothing seemed to be changed: Command Prompt still didn't recognize Python codes. Finally I got it done by manually setting the environment variables in Windows System Properties.
Then I tried to figure out what was wrong with this script and found that it does not take effect until a reboot or log off. It's not mentioned in the content or output of the script, making it puzzling.
The cause of this inconvenience is that though the script changes the env vars, applications don't refer to the new values automatically. It is explained in a Microsoft KB article(http://support.microsoft.com/kb/104011) -- "However, note that modifications to the environment variables do not result in immediate change. For example, if you start another Command Prompt after making the changes, the environment variables will reflect the previous (not the current) values. The changes do not take effect until you log off and then log back on."
The article also provided a method to refresh the environment variables immediately -- "To effect these changes without having to log off, broadcast a WM_SETTINGCHANGE message to all windows in the system, so that any interested applications (such as Windows Explorer, Program Manager, Task Manager, Control Panel, and so forth) can perform an update."
I am going to create a PR which implements it by using ctypes.windll.user32.SendMessageTimeoutW() to broadcast the WM_SETTINGCHANGE message.
components: Demos and Tools, Windows, ctypes
nosy: neeverett, paul.moore, steve.dower, tim.golden, zach.ware
title: Make win_add2path.py take effect without having to log off
versions: Python 3.7
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce