Add, delete, sort, and backup Windows environment variables including PATH.
In the AutoHotkey v2 version of this script an OSError is thrown instead of the error value "-1".
- Automatic REG_SZ and REG_EXPAND_SZ detection
- Backup before you make any changes with
EnvUserBackup()
andEnvSystemBackup()
- Sort your messy Windows PATH in alphabetical order and remove duplicate entries.
- Edit both system and user path with separate commands.
- Broadcast changes to PATH in the current AutoHotKey script and System-wide.
- Supports relative paths with just in time conversion.
- Rename Environment (for v1).ahk to Environment.ahk.
- In the same directory create a new script with the following code.
#include Environment.ahk
Env_UserBackup(), Env_SystemBackup() ; Always backup!
MsgBox % userpath := Env_UserRead("PATH") ; Display the user path.
Env_UserBackup()
Env_SystemBackup()
Env_UserAdd("PATH", "C:\bin")
Env_UserSub("PATH", "C:\bin")
Env_UserAdd("PATH", "..\project1\bin")
Env_UserNew("NUMBER_OF_GPU_CORES", "9")
key := Env_UserRead("NUMBER_OF_GPU_CORES")
; returns 9
Env_UserDel("NUMBER_OF_GPU_CORES")
Env_SystemAdd("PATH", "X:\Backup\bin")
Env_SystemSort("PATH")
Env_SystemRemoveDuplicates("PATH")