![]() |
中国DOS联盟-- 联合DOS 推动DOS 发展DOS --联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum |
| 游客 | 登录 | 注册 | 会员 | 搜索 | 中国DOS联盟 |
|
中国DOS联盟论坛 现在时间是 2026-09-13 22:57 |
共 47,812 主题排行 / 349,916 发帖 / 今日 0 篇 / 48,268 会员排行 |
| 论坛回收站 » 请问一份批处理 |
| 可打印版本 1,730 / 2 |
| 第1楼 jodyzyx | 发表于 2010-03-17 13:42 |
| 新手上路 发帖 5 积分 12 | |
|
请问一份批处理 本人刚接触批处理不久,加上对DOS命令了解的也不全 现有一个批处理请请教大家。希望可以在语句旁帮我写上注释,谢谢大家。
我有一个软件,运行的时候它会读取某一个地址的验证文件,如 xxx.xx.net/123456/update.txt 现在别人把这个验证文件从服务器上面拿下来了,而我想继续用这个软件,所以想到了HOSTS文件,我想实现的是:备份系统原来的HOSTS,然后在HOSTS里面的最后写入(如:192.168.0.1 xxx.xx.net) 然后启动软件1分钟后将这个改写过的HOSTS文件删掉,将刚刚备份的HOSTS文件还原,并将备份文件删掉。找了个类似的批处理 但是看不懂。希望大家可以帮忙帮我在语句旁帮我写上注释。 例子: cd /d %windir%\system32\drivers\etc del hosts.bak ren hosts hosts.bak for /f "eol=# tokens=1,2" %%i in (hosts.bak) do call :checkvalue %%i %%j goto end :checkvalue echo %2 | find /i "szshequ.com" if %errorlevel%==1 (echo %1 %2 >>hosts) :end type C:\WINDOWS\system32\drivers\etc\hosts type C:\WINDOWS\system32\drivers\etc\hosts | find "szshequ.com" && goto yes ::echo 192.168.2.188 szshequ.com >> "" echo 192.168.2.188 szshequ.com >> C:\WINDOWS\system32\drivers\etc\hosts echo 192.168.2.188 www.szshequ.com >> C:\WINDOWS\system32\drivers\etc\hosts echo 192.168.2.188 bbs.szshequ.com >> C:\WINDOWS\system32\drivers\etc\hosts |
|
| 第2楼 Hanyeguxing | 发表于 2010-03-17 17:23 |
| 银牌会员 发帖 897 积分 1,039 来自 在地狱中仰望天堂 | |
|
cd /d %windir%\system32\drivers\etc
rem 进入到%windir%\system32\drivers\etc目录,并以此为当前目录 del hosts.bak rem 删除文件 ren hosts hosts.bak rem 重命名文件 for /f "eol=# tokens=1,2" %%i in (hosts.bak) do call :checkvalue %%i %%j rem 读取解析文件hosts.bak,并以空格制表符为分隔,忽略所有#开头的行。 rem 循环执行时候call 标签:checkvalue。同时,将解析时获取的变量%%i %%j传递给标签:checkvalue。 rem 顺便说一下,如果此标签段后还有别的命令,需要使用goto :eof。 goto end rem 跳到end :checkvalue echo %2 | find /i "szshequ.com" rem 查找%2参数(也就是%%j)中是否有szshequ.com if %errorlevel%==1 (echo %1 %2 >>hosts) rem 如果没有则输出%1和%2,也就是%%i和%%j :end type C:\WINDOWS\system32\drivers\etc\hosts type C:\WINDOWS\system32\drivers\etc\hosts | find "szshequ.com" && goto yes rem 在文件中查找szshequ.com是否存在,是则条转到yes。实际这里使用findstr更合适。 ::echo 192.168.2.188 szshequ.com >> ""下面是输出到文件 echo 192.168.2.188 szshequ.com >> C:\WINDOWS\system32\drivers\etc\hosts echo 192.168.2.188 www.szshequ.com >> C:\WINDOWS\system32\drivers\etc\hosts echo 192.168.2.188 bbs.szshequ.com >> C:\WINDOWS\system32\drivers\etc\hosts rem 此批处理不完整。按你的要求,批处理没必要弄这么复杂 [ Last edited by Hanyeguxing on 2010-3-17 at 17:26 ] |
|
| 第3楼 jodyzyx | 发表于 2010-03-17 17:34 |
| 新手上路 发帖 5 积分 12 | |
|
谢谢 谢谢你的解释,你说这个批处理不完整,那么如果要按照我的要求写批处理的话,请问批处理代码要怎么写呀,代码当然能越少越好啦。。。。
如果可以的话麻烦帮我一下,谢谢了。。。。 |
|
|
[ 联系联盟系统管理团队 -
中国DOS联盟 -
标准版 ] Sponsored by ifanr Inc | © 2001–2023 |