update windows hosts file via .bat

This is how you update windows hosts file via .bat

replace 127.0.0.1 localhost with the host entry you need

@echo off
REM Creating a Newline variable (the two blank lines are required!)
set NLM=^
set NL=^^^%NLM%%NLM%^%NLM%%NLM%
ECHO. >> "%systemroot%\system32\drivers\etc\hosts"
findstr "127.0.0.1 localhost" "%systemroot%\system32\drivers\etc\hosts"
if %errorlevel%==0 goto msg
echo %NL%%NL%%NL%%NL%127.0.0.1 localhost >> "%systemroot%\system32\drivers\etc\hosts"
C:\WINDOWS\NOTEPAD.EXE C:\WINDOWS\SYSTEM32\DRIVERS\etc\HOSTS
echo. Added host entries
goto :eof
:msg
cls
echo. The Host file is already up-to-date!

C:\WINDOWS\NOTEPAD.EXE C:\WINDOWS\SYSTEM32\DRIVERS\etc\HOSTS


One comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.