I've been using following commands to set/remove user/system environment variables:
SYSTEM:
setx -m PATH "%PATH%C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;"
USER:
setx VAR1 "CONTENT OF VAR1"
Later I've found those limitations:
- If the
%PATH%
is too long then I get following warning and the%PATH%
variable is truncated:
WARNING: The data being saved is truncated to 1024 characters.
- As the help for
setx
command says:
When you use Setx.exe to clear an environment variable value, the environment variable name is not affected
In other words when I run setx -m OCVLIBDIR ""
then the OCVLIBDIR
will not be deleted but rather empty.
How can I overcome those limitations?
PS: I prefer tools that are part of Windows 10 (e.g. PowerShell) but it is not problem to use also 3rd party tools (although it seems to me like overkill).
PPS: I know it is possible to edit variables via windows GUI, registers or some 3rd party GUI tools but I prefer scripts because I can have scripted multiple scenarios and fast switch between them.This is useful when I'm experimenting with various libraries on my system (e.g. various versions of opencv etc.).