reg命令给windows添加环境变量

2013-04-03

windows,我们常常点击系统属性,手动添加环境变量,其实我们可以通过命令修改注册表实现此类操作。执行reg /?可获取更多帮助。

例1:修改PATH环境变量.bat

@echo off

path %PATH%;e:\small\pstool
set tmp=%path%
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v "Path" /t REG_SZ /f /d "%tmp%"

例2:添加NLS_LANG环境变量.bat

@echo off

set parameter_name="NLS_LANG"
set parameter_value="AMERICAN_AMERICAN.ZHS16GBK"
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v "%parameter_name%" /t REG_SZ /f /d "%parameter_value%"

例3:添加带空格的NLS_LANG环境变量.bat

@echo off

set value=SIMPLIFIED CHINESE_CHINA.ZHS16GBK
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v "NLS_LANG" /t REG_SZ /f /d "%value%"

例4:删除JAVA_HOME环境变量.bat

@echo off

set parameter_name="JAVA_HOME"
reg delete "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v "%parameter_name%" /f

分类:操作系统 | 标签: |

相关日志

评论被关闭!