script.bat 可以更改 Windows PATH 环境变量吗
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3835518/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can a script.bat make changes to Windows PATH Environment Variable
提问by Berming
I'm trying to write a script that when clicked will add a couple of entries to the PATH Environment variable in Windows, instead of making the changes manually. I see .bat files being used all the time on Windows for a variety of reasons, so can a .bat script help me with something like that?
我正在尝试编写一个脚本,当单击该脚本时,它将向 Windows 中的 PATH 环境变量添加几个条目,而不是手动进行更改。我看到 .bat 文件由于各种原因一直在 Windows 上使用,那么 .bat 脚本可以帮助我解决类似问题吗?
I actually need to download a zip from a location on the Internet, extract it to a specified location, then update the PATH in environment variable. Never done this before so any hints appreciated.
我实际上需要从 Internet 上的某个位置下载一个 zip,将其解压缩到指定位置,然后更新环境变量中的 PATH。从来没有这样做过,所以任何提示表示赞赏。
回答by drhanlau
If you wish to change/update the PATH permanently in the environment variable, you can use the SETX command e.g.
如果您希望在环境变量中永久更改/更新 PATH,您可以使用 SETX 命令,例如
setx path "%PATH%;C:\New Folder"
For more details information on %PATH% and other variables to access to system folder, refer to http://vlaurie.com/computers2/Articles/environment.htm
有关访问系统文件夹的 %PATH% 和其他变量的更多详细信息,请参阅http://vlaurie.com/computers2/Articles/environment.htm