如何从cmd永久更新PATH变量?视窗 [英] How to update PATH variable permanently from cmd? Windows

查看:147
本文介绍了如何从cmd永久更新PATH变量?视窗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我从cmd执行设置PATH =%PATH%; C:\\Something\\bin ,然后执行 echo %PATH%我看到这个字符串在路径中添加。如果我关闭并打开cmd,那么新的字符串不在PATH中。如何在将来为所有进程从cmd中永久更新PATH,而不仅仅是为当前进程?
我不想这样做通过转到系统属性 - >高级 - >环境变量,并有更新PATH。

If I execute set PATH=%PATH%;C:\\Something\\bin from cmd and then execute echo %PATH% I see this string added in path. If I close and open cmd, that new string is not in PATH. How can I update PATH permanently from cmd for all processes in future, not just for the current process? I don't want't to do this by going to System Properties -> Advanced -> Environment variables and there update PATH.

此命令必须从java应用程序执行(我的其他问题)。

This command must be executed from java application (my other question).

推荐答案

有关如何执行此操作的文档可以在 MSDN 。关键摘要是:

The documentation on how to do this can be found on MSDN. The key extract is this:


要以编程方式添加或修改系统环境变量,请将它们添加到 HKEY_LOCAL_MACHINE \System\ CurrentControlSet\Control\Session Manager\Environment 注册表项,然后广播 WM_SETTINGCHANGE 消息。

To programmatically add or modify system environment variables, add them to the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment registry key, then broadcast a WM_SETTINGCHANGE message with lParam set to the string "Environment". This allows applications, such as the shell, to pick up your updates.

请注意,您的应用程式需要提升管理员权限,才能可以修改此键。

Note that your application will need elevated admin rights in order to be able to modify this key.

您在注释中表示您将很乐意只修改每个用户的环境。请通过修改 HKEY_CURRENT_USER\Environment 中的值来执行此操作。与之前一样,请确保您广播了 WM_SETTINGCHANGE 消息。

You indicate in the comments that you would be happy to modify just the per-user environment. Do this by editing the values in HKEY_CURRENT_USER\Environment. As before, make sure that you broadcast a WM_SETTINGCHANGE message.

您应该能够使用JNI注册表类。

You should be able to do this from your Java application easily enough using the JNI registry classes.

这篇关于如何从cmd永久更新PATH变量?视窗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆