[issue30374] Make win_add2path.py take effect without having to log off
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 messages: 293727 nosy: neeverett, paul.moore, steve.dower, tim.golden, zach.ware priority: normal severity: normal status: open title: Make win_add2path.py take effect without having to log off type: behavior versions: Python 3.7 ___ Python tracker <http://bugs.python.org/issue30374> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue30374] Make win_add2path.py take effect without having to log off
Changes by neeverett : -- pull_requests: +1688 ___ Python tracker <http://bugs.python.org/issue30374> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue30374] Make win_add2path.py take effect without having to log off
neeverett added the comment: I didn't noticed that there are other problems with this script. So maybe it needs a complete rewrite instead. But I doubt if it should be simply deleted. Actually I think there is a litte problem with the installer: "add Python to PATH" is not selected by default when installing. I don't know if there's a reason for this. But beginners like me tend to install Python under the default configs therefore it is possible that they later find Python is not in the system PATH. Under this condition it is at least more convenient than manually setting the env vars. -- ___ Python tracker <http://bugs.python.org/issue30374> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue30374] Make win_add2path.py take effect without having to log off
neeverett added the comment: I think the original author adds the relative path "%APPDATA%..." with the intention to keep it effective even when the set path of APPDATA changes. However that compulsively changes the type of PATH var to REG_EXPAND_SZ. It is reasonable that the type of PATH var should not be changed. So I think when the type is REG_SZ, not adding the %APPDATA% path and instead adding the absolute path of it should be a good idea. I just modified my PR and fixed it this way, along with other problems that Eryk Sun mentioned. -- ___ Python tracker <http://bugs.python.org/issue30374> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue30374] Make win_add2path.py take effect without having to log off
Changes by neeverett : -- pull_requests: +1740 ___ Python tracker <http://bugs.python.org/issue30374> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com