@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
From:http://tw.wingwit.com/Article/program/qrs/201404/30405.html