Add new directory in PATH user variable with Setx don't work

霸气de小男生 提交于 2020-11-29 23:47:03

问题


In a .bat script, I want to add a specific list of directory in PATH user variable.

Initially, path is like this :

C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Novell\iPrint;C:\Program Files\WindowsPowerShell\Scripts\HP.ClientScriptLibrary;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\dotnet\;C:\Program Files (x86)\Yarn\bin\;C:\Program Files\Docker\Docker\resources\bin;C:\ProgramData\DockerDesktop\version-bin;C:\Users\myuser\AppData\Local\Microsoft\WindowsApps;C:\Program Files (x86)\Graphviz2.38\bin;

I use this command :

setx WAC_PATH "c:\mydir1;c:\mydir2"
setx Path "%Path%;%%WAC_PATH%%"

I use "%%" because I want to group my new directories in a single variable (WAC_PATH) and use it directly into PATH variable.

As result, The WAC_PATH is correctly define in the user environment variable. But, PATH is altered : many occurrence of initial configuration are duplicated and I have several occurrences of C:\WINDOWS and C:\WINDOWS/SYSTEM32

C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Novell\iPrint;C:\Program Files\WindowsPowerShell\Scripts\HP.ClientScriptLibrary;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\dotnet\;C:\Program Files (x86)\Yarn\bin\;C:\Program Files\Docker\Docker\resources\bin;C:\ProgramData\DockerDesktop\version-bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Novell\iPrint;C:\Program Files\WindowsPowerShell\Scripts\HP.ClientScriptLibrary;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\dotnet\;C:\Program Files (x86)\Yarn\bin\;C:\Program Files\Docker\Docker\resources\bin;C:\ProgramData\DockerDesktop\version-bin;C:\Users\myuser\AppData\Local\Microsoft\WindowsApps;C:\Program Files (x86)\Graphviz2.38\bin;;C:\WINDOWS;C:\WINDOWS\System32;C:\WINDOWS;C:\WINDOWS\System32;C:\WINDOWS;C:\WINDOWS\System32;C:\WINDO

I think that variable WAC_PATH is added at the end of PATH but the length exceed 1024.

Why all these values are duplicated (I should have the initial path value with only the reference to WAC_PATH at the end ) ?

来源:https://stackoverflow.com/questions/64837312/add-new-directory-in-path-user-variable-with-setx-dont-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!