Home > Network Management > Batch File to append entry to hosts file on local or remote PC

Batch File to append entry to hosts file on local or remote PC

February 28th, 2014

These are two small Microsoft Windows batch files which will enable administrators to append entry to hosts file on local or remote PC:

 First determine the computer name:

C:\Users\dmatthews\Desktop>hostname
L00151267

Execute this batch file:

@echo off
SET Compname=%COMPUTERNAME%
SET filename=\\%Compname%\C$\WINDOWS\system32\drivers\etc\hosts
echo. >> %filename%
echo 172.23.191.65 autodiscover.dstsystems.com >> %filename%
type \\%Compname%\C$\WINDOWS\system32\drivers\etc\hosts

This version can be located on a remote share and executed over the network by the end-user:

C:\Users\dmatthews\Desktop>type hostchg.bat
@echo off
echo Enter Computer name:
echo.
SET /P Compname=[WSID:]
SET filename=\\%Compname%\C$\WINDOWS\system32\drivers\etc\hosts
echo. >> %filename%
echo 127.0.0.1 bbc.co.uk >> %filename%
type \\%Compname%\C$\WINDOWS\system32\drivers\etc\hosts

 

 

 

Categories: Network Management Tags:
Comments are closed.