欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

修改ini文件的批处理与vbs代码

程序员文章站 2022-06-09 22:21:35
批处理代码: @echo off >tmp.ini for /f "tokens=1* delims=:" %%i in ('findstr /n ".*...

批处理代码:

@echo off >tmp.ini
for /f "tokens=1* delims=:" %%i in ('findstr /n ".*" 文件位置') do (
   if "%%j"=="" (echo.>>tmp.ini) else (
      echo %%j|find "被替换内容">nul&&(
        call set tp=%%j&call echo %%tp:被替换内容=替换内容%%>>tmp.ini)||(
           >>tmp.ini echo %%j)
   )
)
copy tmp.ini 文件位置 /y >nul||(attrib -s -a -r -h 文件位置& copy tmp.ini 文件位置 /y >nul)
del tmp.ini
pause 

用vbs更简单:
vbs代码:

on error resume next 
dim fso,txtfl,str
set fso = createobject("scripting.filesystemobject")
set txtfl = fso.opentextfile ("文件位置",1)
str = replace ( txtfl.readall,"被替换内容","替换内容")
set txtfl = fso.opentextfile ("文件位置",2)
txtfl.write str 
txtfl.close

批处理打开和关闭文件

关闭 两种命令方法:

taskkill /f im "要关闭的进程名"

ntsd -c q -pn "要关闭进程名"

后者更强一点..~!

打开程序:

start "" “位置/程序名”

修改ini文件的批处理与vbs代码

相关标签: 修改ini