更改以从环境变量 PATH 中删除路径
我正在尝试使用命令行实现来更改 PATH 环境变量以删除路径,因此我不必在一堆计算机上手动删除它。
我发现了这个,我似乎无法让它工作:
%Path:str1=str2%
str1
是路径,str2
是 null,我不知道如何设置它在命令行上设置为 null。
如果有其他方法,我很乐意尝试。
I'm trying to use a command line implementation to change the PATH
environment variable to remove a path, so I don't have to manually remove it on a bunch of machines.
I have found this, which I can't seem to get it to work:
%Path:str1=str2%
str1
is the path and str2
is null, which I'm not sure how to set it to null on the command line.
If there is another way, I would be glad to give it a try.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不确定为什么这对您不起作用,但这里有一个有效的示例(至少在 Windows XP 上)。
这将删除“c:\windows\system32;”来自路径变量。确保末尾有
;
,否则可能会部分删除其他一些路径。请记住,这只会影响命令提示符的当前实例。如果退出或在不同的命令提示符下工作,对环境变量所做的任何更改都将丢失。
Not sure why this didn't work for you, but here is an example that does work (at least on Windows XP).
This will remove "c:\windows\system32;" from the path variable. Make sure you have the
;
on the end otherwise it may partially remove some other paths.Remember that this will only affect the current instance of the command prompt. If you quit or work in a different command prompt, any changes you made to the environment variables will be lost.
使用 VBScript,您可以获得路径变量:
然后拆分以获取片段数组:
将任何条目设置为空字符串以删除它们:
然后重建路径:
Using VBScript, you can get the path variable:
Then split to get an array of the pieces:
Set any entries to an empty string to remove them:
Then reconstruct the path:
更改当前进程和/或子进程的 Path 变量与更改 Windows 启动时变量的默认加载状态之间存在差异。
您或许可以使用 WMI 来完成此操作。如果没有,请使用 procmon 看看编辑系统变量时“我的电脑”正在做什么。这将使您能够编写脚本。
There's a difference between changing Path variable for a current process and/or for child processes, to changing the default load state of the variable when windows starts.
You might probably be able to do it with WMI. If not, take procmon and see what "My Computer" is doing when you edit a system variable. This will enable you to write a script.
在 vbScript 命令文件 (.cmd) 或 (.bat) 中,您可以使用以下命令删除环境变量:
In a vbScript command file (.cmd) or (.bat), you can use the following to remove an environment variable:
有一种更简单的方法可以代替使用命令提示符。右键单击“我的电脑”进入高级系统设置,在底部单击环境变量,突出显示“路径”,然后单击“编辑”。您可以在其中添加、删除或更改路径中的目录顺序。
希望这对某人有帮助,
2
There is an easier way instead of using the command prompt. Right click on "My Computer" go to advanced system settings, at bottom click Environment variables, highlight "PAth" and click "Edit". You can add, delete or change the order of directories in your path there.
Hope this helps somebody,
2