本帖最后由 老刘1号 于 2017-4-1 23:15 编辑
实例:- @echo off
- Call :Editini "%~dp0Test.ini" Path ",SystemPath=%HOMEDRIVE%"
- %Path节中添加键值%
-
- Call :Editini "%~dp0Test.ini" Path "我是来凑数的~~~=我是随意字符串"
- %Path节中删除键值%
-
- Call :Editini "%~dp0Test.ini" Path "userPath=,userPath=%USERPROFILE%"
- %强制更改Path节中的UserPath键值%
-
- Call :Editini "%~dp0Test.ini" "Others Thing" "作者=不知道,作者=老刘~,2"
- %嘿嘿,如果“不知道”作者,将“不知道”替换为"老刘~“,否则不执行操作%
-
- Call :Editini "%~dp0Test.ini" "嘿嘿嘿" "s1="
- %清除嘿嘿嘿节的注释,前提是被包裹在项和节之间%
-
- Start %~dp0Test.ini
-
- %——————————————————————————————%
-
- GOTO :Eof
- :EditIni
- @Echo off
- Pushd %Tmp%
- (For %%a in (
- "[Version]"
- "Signature=$Chicago$"
- "[DefaultInstall]"
- "UpdateInis=2333"
- "[2333]"
- ) Do Echo %%~a)>.\inftmp.Inf
- Echo "%~1","%~2",%~3 >>.\inftmp.Inf
- RUNDLL32 SETUPAPI.DLL,InstallHinfSection ^
- DefaultInstall 128 .\inftmp.INF
- Popd
复制代码 附带Test.INI(与批处理在同一目录):- [Path]
- winPath=C:\windows
- userPath=sx
- 我是来凑数的~~~=2333
- [Others Thing]
- 作者=不知道
- [嘿嘿嘿]
- ;;‘我是注释1号~~~~~s~~~~~~~d~~~~~~~~~~~~~~~~~~s~~~~~
- ;;‘我是注释2号~~d~~~~~~~~~~~~~~~w~~~~~~~~~s~~~~~~~~~
- ;;‘我是注释3号~w~~~~~~~~~~~~~~~~~~~~~~~~~~z~~~s~~~~~
- ;;‘我是注释4号~~~~~~~~~a~~~~~~~~~~~~a~~~~~~z~~~~~~~~
- ;;‘我是注释5号~~~~~~~~~~~~~~~s~~~~~~~~~~w~~~z~~~~~~~
- ;;‘我是注释6号~~~~~~~~~~w~~~~~s~~~~~~~~~~~~~~~~~~s~~
- ;;‘我是注释7号~~~~~~x~~~~~~~~~~~~~~~~s~~~~~~~~~~~s~~
- s1=
复制代码 这算是比较人性化的实例代码了吧~ |