@echo >>C:\Windows\System\Drivers\etc\hosts 这样就是换一行写入 如果还想换一行就写 复制代码 代码如下: @echo >>C:\Windows\System\Drivers\etc\hosts @echo >>C:\Windows\System\Drivers\etc\hosts @echo ibmrac >>C:\Windows\System\Drivers\etc\hosts @echo ibmrac >>C:\Windows\System\Drivers\etc\hosts @echo vipibmrac >>C:\Windows\System\Drivers\etc\hosts @echo vipibmrac>>C:\Windows\System\Drivers\etc\hosts @echo ssosvr>>C:\Windows\System\Drivers\etc\hosts 复制代码 代码如下: @echo off set stHosts= ssosvr FOR /F eol=# tokens= delims= %%i in (%systemroot%\system\drivers\etc\hosts) do if %stHosts%==%%i exit echo %stHosts%>> %systemroot%\system\drivers\etc\hosts 由于测试需要经常修改本机host可以用脚本修改 分别做两个批处理一个内网一个外网用的时候切换运行即可 如内网bat 复制代码 代码如下: cd /d %windir%\system\drivers\etc del hostsbak //删除原来备份文件 ren hosts hostsbak //备份现在host for /f eol=# tokens= %%i in (hostsbak) do call :checkvalue %%i %%j goto end :checkvalue echo % | find /i //寻找制定记录删除 if %errorlevel%== (echo % % >>hosts) :end type C:\WINDOWS\system\drivers\etc\hosts type C:\WINDOWS\system\drivers\etc\hosts | find && goto yes ::echo >> echo >> C:\WINDOWS\system\drivers\etc\hosts echo >> C:\WINDOWS\system\drivers\etc\hosts echo >> C:\WINDOWS\system\drivers\etc\hosts echo >> C:\WINDOWS\system\drivers\etc\hosts echo >> C:\WINDOWS\system\drivers\etc\hosts echo >> C:\WINDOWS\system\drivers\etc\hosts echo >> C:\WINDOWS\system\drivers\etc\hosts echo >> C:\WINDOWS\system\drivers\etc\hosts echo >> C:\WINDOWS\system\drivers\etc\hosts echo >> C:\WINDOWS\system\drivers\etc\hosts echo >> C:\WINDOWS\system\drivers\etc\hosts |