admin管理员组

文章数量:1531532

2024年1月13日发(作者:)

方法一:批处理中,修改环境变量,一次性有效(也就是在当前的脚本中有效)CMD中运行set path==%path%;d:/mypath用 set path可以查看,当前的环境变量

方法二 :批处理中,修改环境变量,永久有效::更改path环境变量值,新增e:toolswmic ENVIRONMENT where "name='path' and username=''" setVariableValue="%path%;e:tools"

另外介绍些关于wminc的用法(简单又实用)

::获取temp环境变量wmic ENVIRONMENT where "name='temp'" get UserName,VariableValue::新增系统环境变量home,值为%HOMEDRIVE%%HOMEPATH%wmic ENVIRONMENT create name="home",username="",VariableValue="%HOMEDRIVE%%HOMEPATH%"::删除home环境变量wmic ENVIRONMENT where "name='home'" delete::获取temp环境变量wmic ENVIRONMENT where "name='temp'" get UserName,VariableValue::更改path环境变量值,新增e:toolswmic ENVIRONMENT where "name='path' and username=''" setVariableValue="%path%;e:tools"::新增系统环境变量home,值为%HOMEDRIVE%%HOMEPATH%wmic ENVIRONMENT create name="home",username="",VariableValue="%HOMEDRIVE%%HOMEPATH%"::删除home环境变量wmic ENVIRONMENT where "name='home'" delete一般来说,wmic创建或修改的系统变量不用重启windows生效,但如果你发现在DOS窗下检测不生效的话,你试着关闭 DOS窗,再检测一次.就生效了.如果你的批处理想不关闭而直接让新的变量给下级程序应用可以这样写

view plaincopy to clipboardprint?::检查path中有没有e:tools(有就跳到run,没有就接着执行)echo %path%|findstr /i "e:tools"&&(goto run)

::先添加,防止没有时修改出错wmic ENVIRONMENT create name="path",VariableValue="e:tools;%path%"::再修改,防止已有时添加出错

wmic ENVIRONMENT where "name='path' and username=''" setVariableValue="e:tools;%path%"::再即时应用set "path=e:tools;%path%"

:runstart 程序.exe::检查path中有没有e:tools(有就跳到run,没有就接着执行)echo %path%|findstr /i "e:tools"&&(goto run)::先添加,防止没有时修改出错wmic ENVIRONMENT create name="path",VariableValue="e:tools;%path%"::再修改,防止已有时添加出错wmic ENVIRONMENT where "name='path' and username=''" setVariableValue="e:tools;%path%"::再即时应用set "path=e:tools;%path%":runstart 程序.exe

本文标签: 环境变量修改系统防止批处理