从设置CMD.EXE一个持久的环境变量 [英] Set a persistent environment variable from cmd.exe
问题描述
我必须设置在不同的Windows机器的环境变量,但我不想手动得到我的电脑
I have to set environment variables on different windows machines, but I don't want to be bothered changing them manually by getting on the properties screen of "My Computer"
我要在命令行中做到这一点,有一个批处理文件。据我了解,使用集将只更改变量,我会在命令窗口中调用该进程。
I want to do it from the command line, with a batch file. As far as I understand, using set will only change the variable for the processes I will call in the command window.
我想肯定是设置它,所以后来,运行一个新的进程的时候,它会使用我已设置这些新的设置。有没有办法做到这一点从命令行?
I want to set it definitely, so later, when running a new process, it will use those new settings I have set. Is there a way to do that from the command line ?
推荐答案
的环境变量MSDN文档告诉你该怎么做:
要以编程方式添加或修改系统环境变量,将它们添加到 HKEY_LOCAL_MACHINE \\系统\\ CurrentControlSet \\控制\\会话管理\\环境的注册表键,然后播出的 WM_SETTINGCHANGE 消息与lParam参数设置为字符串环境。这使得应用程序,如外壳,拿起你的更新。
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.
您当然会需要做的这个管理权限。据我所知,没有办法从广播Windows批处理Windows消息,所以你需要写一个小程序来做到这一点。
You will of course need admin rights to do this. I know of no way to broadcast a windows message from Windows batch so you'll need to write a small program to do this.
这篇关于从设置CMD.EXE一个持久的环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!