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 <rep...@bugs.python.org>
<http://bugs.python.org/issue30374>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to