wordpress   发布时间:2022-04-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了windows-7 – Windows批次:如何添加主机条目?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我想使用这个批处理脚本通过使用 windows批次自动添加新的条目到我的主机文件。 不幸的是,该脚本只是向hosts文件添加了一行,当我以管理员身份运行脚本时,是怎么回事? @echo off set hostspath=%windir%\System32\drivers\etc\hosts echo 62.116.159.4 ns1.intranet.de >> %hostspath% ec
我想使用这个批处理脚本通过使windows批次自动添加新的条目到我的主机文件。 @H_403_1@不幸的是,该脚本只是向hosts文件添加了一行,当我以管理员身份运行脚本时,是怎么回事?

@echo off

set hostspath=%windir%\System32\drivers\etc\hosts

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%\system32\drivers\etc\hosts
IF %ERRORLEVEL% NEQ 0 ECHO %NEWLINE%^62.116.159.4 ns1.intranet.de>>%WINDIR%\System32\drivers\etc\hosts

FIND /C /I "ns2.intranet.de" %WINDIR%\system32\drivers\etc\hosts
IF %ERRORLEVEL% NEQ 0 ECHO %NEWLINE%^217.160.113.37 ns2.intranet.de>>%WINDIR%\System32\drivers\etc\hosts

FIND /C /I "ns3.intranet.de" %WINDIR%\system32\drivers\etc\hosts
IF %ERRORLEVEL% NEQ 0 ECHO %NEWLINE%^89.146.248.4 ns3.intranet.de>>%WINDIR%\System32\drivers\etc\hosts

FIND /C /I "ns4.intranet.de" %WINDIR%\system32\drivers\etc\hosts
IF %ERRORLEVEL% NEQ 0 ECHO %NEWLINE%^74.208.254.4 ns4.intranet.de>>%WINDIR%\System32\drivers\etc\hosts

大佬总结

以上是大佬教程为你收集整理的windows-7 – Windows批次:如何添加主机条目?全部内容,希望文章能够帮你解决windows-7 – Windows批次:如何添加主机条目?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。