安装程序更改 PATH 变量,更改不会显示在命令 Shell 中
我向安装程序添加了自定义安装操作,以将安装目录之一添加到系统 PATH 环境变量中。 运行安装程序后,PATH 变量会反映更改(当我通过控制面板::系统小程序访问它时),但当我启动新的命令 shell 时,PATH 变量不会反映更改。 是不是有什么我没做的事情导致了这个?
I added a custom install action to my installer to add one of my installation directories to the System PATH environment variable. After I run the installer, the PATH variable reflects the changes (when I access it through the Control Panel::System applet), but when I start a new command shell, the PATH variable does not reflect the changes. Is there something I'm failing to do, that causes this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你是如何添加环境变量的?
无需使用任何外部工具,您可以将其添加到注册表< /a>. 然后,打开新命令窗口的测试将反映您的更改。
How are you adding the environment variable?
Without using any external tools, you can add it to the registry. Then, your test of opening a new command window will reflect your change.
为什么要使用 CustomAction 来实现此目的? Windows Installer 本机支持修改环境变量。 另外,我认为当环境变量发生变化时,Windows Installer 会发送广播消息来更新系统。 这可能意味着你不需要重新启动......但我已经有一段时间没有尝试过YMMV了。
Why are you using a CustomAction for this? The Windows Installer supports modifying environment variables natively. Also, I think the Windows Installer sends a broadcast message to update the system when environment variables change. That may mean you don't need to reboot... but it's been a while since I tried so YMMV.
http://support.microsoft.com/kb/310519 表示对于系统环境变量(哪个 PATH 是其中之一)需要重新启动,尽管我有一种感觉注销然后重新打开可能就足够了。
http://support.microsoft.com/kb/310519 says that for system environment variables (which PATH is one of) requires a restart, although I have a feeling that logging off and on may be enough.
你如何启动命令外壳? 用任务管理器?
我怀疑您可能是从资源管理器启动它 - 如果我没记错的话,这可能意味着您正在继承父进程(在本例中为 Windows 资源管理器)PATH 变量。 由于这是在安装程序运行之前设置的,因此您会看到旧值。
不确定这是否有帮助......
How are you starting the command shell? With the TaskManager?
I suspect you might be starting it from Explorer - if I remember correctly, this could meen that you are inheriting the parent processes (Windows Explorer in this case) PATH variable. Since that was set before your installer ran, you see the old value.
Not sure if this helps...
我认为这取决于您如何启动新的命令 shell。 例如,当您更改“系统属性”下的 PATH 环境变量时,只有在打开新的命令提示符后才会反映更改。 我认为当您启动新的“cmd”进程(例如从“运行”对话框)时,您会获得所有环境变量的新副本,但如果您以不同的方式启动命令提示符,则不会。
对于通过类似脚本完成的操作,您可能需要重新启动才能注意到更改。
I think this depends on how you are starting the new Command shell. For example, when you change the PATH environment variable under System properties, the change isn't reflected until you open a new Command prompt. I think when you launch a new "cmd" process (from the Run dialog for example), you get a fresh copy of all environment variables, but if you launch the command prompt a different way then you do not.
For something done thru a script like that, you may need to restart before you notice the change.