电脑故障

位置:IT落伍者 >> 电脑故障 >> 浏览文章

用批处理修改host文件的代码


发布日期:2023/1/24
 
@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

上一篇:批处理程序中的“多线程”处理代码

下一篇:net use 命令集合详解()