标签:
(1) 通过wmic命令完成对系统环境变量的设定,xp下直接生效,win7需要重启电脑或在电脑-》属性-》高级-》环境变量,下来点确定
@echo off
set regpath=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
::echo.
::echo===============================================
::echo 安装设置
::echo===============================================
::echo.
::set /p en=请按 回车键 安装开始!:
::echo.
set pwd=%cd%
::reg add "%regpath%" /v "winrar" /d "%pwd%\compact;" /f
::echo.
::echo 新追加环境变量 path=%pwd%\WinRAR
:: for,/f,"skip=4 token=1,2,*",%%a,in,(‘reg query "%regpath%" /v "path"‘),do,(
:: reg add "%regpath%" /v "path" /d "%%c;%pwd%\compact;%pwd%\conf\bin;%pwd%\lib;" /f
::)
wmic ENVIRONMENT where "name=‘path‘ and username=‘<system>‘" set VariableValue="%PATH%;%pwd%\compact;%pwd%\conf\bin;%pwd%\lib;"
wmic ENVIRONMENT create name="TESSDATA_PREFIX",username="<system>",VariableValue="%pwd%\lib"
echo.
(2)字符串替换,注意要替换字符串里的比较复杂的符号,需要用!!,而该符呈的使用必须setlocal enabledelayedexpansion和endlocal来加标识
::以替换为空的方式删除Path的环境变量
set p=%PATH%
set pwd=%cd%
set replace=%pwd%\compact^;%pwd%\conf\bin^;%pwd%\lib^;
setlocal enabledelayedexpansion
set p=!p:%replace%=!
wmic ENVIRONMENT where "name=‘path‘ and username=‘<system>‘" set VariableValue="%p%;"
endlocal
(3)正常情况的替换将“aabbcc”中的b串替换为空
set a="aabbcc"
set b=%a:b=%
echo %b%
标签:
原文地址:http://blog.csdn.net/zcc_0015/article/details/42060013