windows 强制环境变量更改立即生效
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6452377/
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
Forcing environment variable changes to take effect immediately
提问by dch
I need to change the value of the Cygwin environment variable CYGWIN
on one of my installs from:
我需要CYGWIN
在我的安装之一中更改 Cygwin 环境变量的值:
ntsec tty
back to the default value of:
回到默认值:
ntsec notty
I can do this programmatically via a .reg file:
我可以通过 .reg 文件以编程方式执行此操作:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment]
"CYGWIN"="ntsec notty"
but it doesn't affect current or subsequent command prompts until a reboot. I don't want to have to reboot! Is there any way I can force this change to apply to, at the very least, subsequent command prompts, immediately?
但它不会影响当前或后续的命令提示,直到重新启动。我不想重新启动!有什么方法可以强制此更改至少立即应用于后续命令提示符吗?
回答by dch
This is very easy to fix & you shouldn't kill explorer to do it. TL;DR use:
这很容易修复,你不应该杀死资源管理器来做到这一点。TL; DR 使用:
setx.exe var value
to make changes available in future command windows, and in all active windows processes that support WM_CHANGESETTINGS API. You can do this for system environment vars as well, which will be propagated to services that support this API.
在未来的命令窗口和所有支持 WM_CHANGESETTINGS API 的活动窗口进程中进行更改。您也可以对系统环境变量执行此操作,这些变量将传播到支持此 API 的服务。
This doesn't change the current CMD.exe or cygwin shell as neither of them support it.
这不会改变当前的 CMD.exe 或 cygwin shell,因为它们都不支持它。
In those the humble set var=value or export var=value will need to be done once per shell.
在那些不起眼的 set var=value 或 export var=value 中,每个 shell 需要执行一次。
http://support.microsoft.com/kb/104011for more info.
http://support.microsoft.com/kb/104011了解更多信息。
A+ Dave
A+戴夫