Board logo

标题: 搜索HOSTS并插入行 [打印本页]

作者: zdh     时间: 2006-11-18 05:43    标题: 搜索HOSTS并插入行

想在c:里面找到HOSTS文件(可能是隐藏文件,无后缀的!),并在里面最后一行插入一行文字(如:I o U)。 感激各位帮助我的高手!;)

作者: vkill     时间: 2006-11-18 05:59
for /f "tekons=*" %%? in ('dir /a-d/s/b c:\hosts') do (>>%%? echo I o U)

作者: zdh     时间: 2006-11-18 06:07
出错: 此时不应有 tekons=*" 我的HOSTS不一定在根C盘目录里啊,可能在C盘某个地方。

作者: NaturalJ0     时间: 2006-11-18 06:12
改成 tokens 如果提示文件是只读,那最好先 attrib 处理一下。

作者: ccwan     时间: 2006-11-18 06:19
楼上正解。

作者: vkill     时间: 2006-11-18 06:24
Originally posted by zdh at 2006-11-18 06:07: 出错: 此时不应有 tekons=*" 我的HOSTS不一定在根C盘目录里啊,可能在C盘某个地方。
汗,写错了

作者: 不得不爱     时间: 2006-11-18 06:25
for /f "tokens=*" %%a in ('dir /a-d/s/b c:\hosts') do echo I o U>>%%a

作者: kht000     时间: 2006-11-18 09:56
ATTRIB -A -R -H C:\WINDOWS\SYSTEM32\DRIVERS\ETC\HOSTS ECHO I o U >> C:\WINDOWS\SYSTEM32\DRIVERS\ETC\HOSTS win2003

作者: tao0610     时间: 2006-11-18 13:34
想在drivers\etc下的hosts加入域名解析吧!

作者: zdh     时间: 2006-11-18 21:29
Originally posted by tao0610 at 2006-11-18 01:34 AM: 想在drivers\etc下的hosts加入域名解析吧!
是啊!因为局域网里面用IP地址访问实在太麻烦了,能够解析就最好了!

作者: tao0610     时间: 2006-11-19 15:25
attrib -s -h %systemroot%\system32\drivers\etc\hosts echo 202.108.22.5 www.baidu.com >> %systemroot%\system32\drivers\etc\hosts

作者: hxuan999     时间: 2006-11-23 07:28
学习了

作者: Kinglion     时间: 2007-4-26 00:55    标题: 通过设置HOSTS设置DNS解析的批处理例

@echo off rem ----------------------------------------------- rem Powered by Kinglion Software Workroom rem www.kinglion.org DNS 解析设置程序 rem Don't modify this file rem ----------------------------------------------- if exist %ComSpec% goto nt :9x if not exist %windir%\hosts goto win9xgo if not exist %windir%\hosts.bak goto win9xgo del %windir%\hosts.bak ren %windir%\hosts %windir%\hosts.bak :win9xgo echo 221.212.188.60 www.kinglion.org >> %windir%\hosts goto end :nt if not exist %windir%\system32\drivers\etc\hosts goto ntgo if not exist %windir%\system32\drivers\etc\hosts.bak goto ntgo del %windir%\system32\drivers\etc\hosts.bak ren %windir%\system32\drivers\etc\hosts %windir%\system32\drivers\etc\hosts.bak :ntgo echo 221.212.188.60 www.kinglion.org >> %windir%\system32\drivers\etc\hosts :end

作者: lxmxn     时间: 2007-4-26 01:25
Kinglion 兄考虑问题很全面哈。

作者: zbjit     时间: 2008-9-24 10:03
13楼的脚本太好了,学习

作者: bailang3106     时间: 2008-9-24 14:05
我也放个参考上来..因为配置系统做了一个 @echo off setlocal enabledelayedexpansion echo Y|cacls %windir%\system32\drivers\etc\hosts /g everyone:f attrib -r -a -s -h %windir%\system32\drivers\etc\hosts color 0A echo.>> %windir%\system32\drivers\etc\hosts FOR /F "eol=# tokens=1 delims=" %%i in (LIST.txt) do ( FIND "%%i" %windir%\system32\drivers\etc\hosts IF errorlevel 1 @echo %%i >> %windir%\system32\drivers\etc\hosts ) @echo on @echo 按任意键退出安装程序 @echo. & pause 1>nul 2>nul

作者: bailang3106     时间: 2008-9-24 14:05
list.txt的模板 10.96.100.55 mismidt01.pec.com.cn 10.96.100.56 mismidt02.pec.com.cn 10.96.100.57 mismidt03.pec.com.cn