Board logo

标题: 求一个能编辑hosts文件的批处理 [打印本页]

作者: zhanghong1     时间: 2007-8-28 14:01    标题: 求一个能编辑hosts文件的批处理

求一个能编辑hosts文件的批处理

能否达到这样一个目的:
检测hosts文件里。
若有这一行:
127.0.0.1  www.abc.com
则删除这一行。

这个hosts文件路径在:
C:\WINDOWS\system32\drivers\etc


谢谢各位了
作者: halulove     时间: 2007-8-28 15:12
cd C:\WINDOWS\system32\drivers\etc
findstr /v "127.0.0.1" >hosts.tmp
del hosts
ren hosts.tmp hosts
作者: zhanghong1     时间: 2007-8-28 15:20
精干~~~~~谢谢楼上

执行不了在我这~~~~~~:(

[ Last edited by zhanghong1 on 2007-8-28 at 03:24 PM ]
作者: zhanghong1     时间: 2007-8-28 15:27
@echo off  
cd /d %windir%\system32\drivers\etc
set ip=127.0.0.1
set host=www.abc.com
echo #change test>temp
for /f "eol=# tokens=1,2" %%i in (hosts) do if %%i==%ip% (echo %%i %host%>>temp) else (echo %%i %%j>>temp)
del hosts.bak
ren hosts hosts.bak
ren temp hosts

现在直接删除上边的那个for语句了~~重建hosts文件..呵呵..谢谢~~一时给忘了~~

[ Last edited by zhanghong1 on 2007-8-28 at 03:29 PM ]