熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> 嵌入式開發 >> 正文

用批處理修改host文件的代碼

2022-06-13   來源: 嵌入式開發 
@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
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.