We have an application that is dependant on an entry being in the hosts file. Apparently they decided to update the software, but didn't let us know so now the hosts files are incorrect.
What I want to do is update these files using minimal user interaction. I quickly tossed the following together which will add a new line to the hosts file, but I'm not sure how I would go about removing the old entry.
echo Enter the name for the PC where the Hosts file needs to be updated.
echo.
SET /P Compname=[WSID:]
SET filename=\\%Compname%\C$\WINDOWS\system32\drivers\etc\hosts
echo. >> %filename%
echo 127.0.0.1 [URL="http://www.myaddress.com"]www.myaddress.com[/URL] >> %filename%
start Notepad.exe %filename%
So all this does is takes the computer name and saves it to a variable called Compname. Then it sets the file path to that of the hosts file on the remote computer. I add a blank line (Because the cursor may not be on it's own line, and a blank line really wouldn't hurt anything) then I add in the new configuration (and I just made up some numbers to stick in here). Lastly I open the hosts file. This is how I could clean up the old entry and the blank line if one was left. But I'm thinking there would be a way to search the file and to remove an entry without needing to open the file.