加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows-7 – Windows批次:如何添加主机条目?

发布时间:2020-12-13 21:07:30 所属栏目:Windows 来源:网络整理
导读:我想使用这个批处理脚本通过使用 windows批次自动添加新的条目到我的主机文件。 不幸的是,该脚本只是向hosts文件添加了一行,当我以管理员身份运行脚本时,是怎么回事? @echo offset hostspath=%windir%System32driversetchostsecho 62.116.159.4 ns1.
我想使用这个批处理脚本通过使用 windows批次自动添加新的条目到我的主机文件。

不幸的是,该脚本只是向hosts文件添加了一行,当我以管理员身份运行脚本时,是怎么回事?

@echo off

set hostspath=%windir%System32driversetchosts

echo 62.116.159.4 ns1.intranet.de >> %hostspath%
echo 217.160.113.37 ns2.intranet.de >> %hostpath%
echo 89.146.248.4 ns3.intranet.de >> %hostpath%
echo 74.208.254.4 ns4.intranet.de >> %hostpath%

exit
我会这样做,所以如果脚本多次运行,你不会得到重复的条目。
@echo off

SET NEWLINE=^& echo.

FIND /C /I "ns1.intranet.de" %WINDIR%system32driversetchosts
IF %ERRORLEVEL% NEQ 0 ECHO %NEWLINE%^62.116.159.4 ns1.intranet.de>>%WINDIR%System32driversetchosts

FIND /C /I "ns2.intranet.de" %WINDIR%system32driversetchosts
IF %ERRORLEVEL% NEQ 0 ECHO %NEWLINE%^217.160.113.37 ns2.intranet.de>>%WINDIR%System32driversetchosts

FIND /C /I "ns3.intranet.de" %WINDIR%system32driversetchosts
IF %ERRORLEVEL% NEQ 0 ECHO %NEWLINE%^89.146.248.4 ns3.intranet.de>>%WINDIR%System32driversetchosts

FIND /C /I "ns4.intranet.de" %WINDIR%system32driversetchosts
IF %ERRORLEVEL% NEQ 0 ECHO %NEWLINE%^74.208.254.4 ns4.intranet.de>>%WINDIR%System32driversetchosts

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读