bat实现文件指定位置的添加和修改?

2025-04-06 02:22:42
推荐回答(2个)
回答1:

不清楚你的实际文件/情况,仅以问题中的样例/说明为据;复制粘贴到记事本,另存为xx.bat,编码选ANSI
@echo off
rem 修改java的部署文件里的特定行及添加/插入几行内容
set #=Any question&set @=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%@% %z%
cd /d "%~dp0"
set "file=%USERPROFILE%\AppData\LocalLow\Sun\Java\Deployment\security\deployment.properties"
if not exist "%file%" (echo;"%file%" not found&pause&exit)
set "s1=deployment.security.revocation.check="
set "s2=install.disable.sponsor.offers="
set "s3=deployment.javaws.jre.0.registered="
type "%file%"|find /v "%s1%"|find /v "%s2%"|find /v "%s3%" > "t.t"
(echo;%s1%NO_CHECK
echo;%s2%false
echo;%s3%true)>>"t.t"
move /y "t.t" "%file%"
echo;%#% +%$%%$%/%@% %z%
pause
exit

回答2:

@echo off
set fn=%USERPROFILE%\AppData\LocalLow\Sun\Java\Deployment\security\deployment.properties
findstr "deployment.security.revocation.check" "%fn%" >nul &&goto :eof
(for /f "tokens=*" %%i in ('type "%fn%"') do (
if "%%i"=="deployment.javaws.jre.0.registered=flase" (echo deployment.javaws.jre.0.registered=true)
if "%%i" neq "deployment.javaws.jre.0.registered=flase" if "%%i"=="deployment.version=7.21" (
echo deployment.security.revocation.check=NO_CHECK
echo %%i
echo install.disable.sponsor.offers=false) else (echo %%i)))>temp.txt
move /y temp.txt "%fn%"