批处理创建和修改环境变量

来源:互联网 发布:社交网络的坏处 编辑:程序博客网 时间:2024/06/05 18:05

创建不存在的环境变量

create name =环境变量名

username="<system>" 表示添加系统环境变量

VariableValue=环境变量

环境变量可以用%~dp0 表示相对于当前批处理的路径

如:%~dp0ThirdPartyLib 等价于D:/ThirdPartyLib

具体事例如下


@echo off  wmic ENVIRONMENT create name="THIRD_PARTY",username="<system>",VariableValue="%~dp0ThirdPartyLib"  echo %THIRD_PARTY%  


修改环境变量

%path%表示原有的环境变量

where "name='path' 用于查找定位要修改的环境变量

具体事例如下

wmic ENVIRONMENT where "name='path' and username='<system>'" set VariableValue="%path%;e:tools"


原创粉丝点击