This script allows adding/modifying/removing environment variables persistently on Windows. It also allows adding entries to the PATH environment variable.
Python, 61 lines
I often install programs that depend on environment variables for their proper operation and require that their executable directory will be add to the PATH. Doing it using the Windows GUI is error-prone and tedious. I have been burned many times. 'enver' is the result. The usage string explains how to use it.
There aren't many :-). Enver parses the command line and works with the Windows registry using the _winreg module to modify the persistent environment. The registry key is SYSTEM\CurrentControlSet\Control\Session Manager\Environment. The treatment of PATH environment variable is special. Enver checks specifically if the env var name is PATH and only appends to it because that's what you usually do. Once everything is done enver broadcasts a WM_SETTINGCHANGE to all the windows in order to make the change visible.
1) Note that at the moment enver doesn't modify the active environment, but only the registry so new command windows will see the changes. So, if you type: 'set' after running enver you won't see any changes. Setting os.environ wouldn't help because the script is executed in a different shell then the host window.
2) There is no way to replace the entire PATH, or to remove entries from the PATH, only to append entries to the PATH. Again, I don't need the other features, if it's important to someone go ahead and add the funtionality.
3) Works on the System environment only. doesn't bother with the User environment (System applies to all users of the machine, User applies to current user only).
4) Most applications (including active cmd.exe Windows) don't react to the broadcast message, so you will not see the cahnge until you restart them.