?
Solved

Best way to fix a Windows Host file with combined entries?

Posted on 2004-11-10
5
Medium Priority
?
177 Views
Last Modified: 2010-05-18
One of the guys had created a Bat file that was to append a new IP and Name (which was in a file called "new_ip.txt" to the end of the Hosts file on either 95 or W2k/XP with the following script...
*******************************
echo off
if exist %windir%\hosts.sam goto win95
if exist %windir%\system32\drivers\etc\hosts goto win2kxp

:win95
c:\
copy %windir%\hosts.sam+c:\new_ip.txt %windir%\hosts.sam
goto exit

:win2kxp
c:\
copy %windir%\system32\drivers\etc\hosts+c:\new_ip.txt %windir%\system32\drivers\etc\hosts
goto exit

:exit
cls
REM Please close this window
*******************************
This apparently worked when he tested it before deployment; but now I'm getting calls about people not being able to get to servers and have diagnosed the problem back to their Host files and the fact that his script works for all unedited Host files that had a carriage return at the end by default, but those that had been edited and saved with new entries, did not.  Thus it caused the two strings to be joined together on one line, so...
"IP1.IP1.IP1.IP1      Name1" in an edited host file became
"IP1.IP1.IP1.IP1      Name1IP2.IP2.IP2.IP2            Name2"
and now I'm left to try and clean this up.

My question would be, how could this script be changed or a new one developed to 1) go back and fix this error and 2) make sure any new ones get done properly?

IP2 and Name 2 are known values, but IP1 and Name1 could be anything and would need to be left with the new entry beneath it.  Thanks.
0
Comment
Question by:AZEMBB
3 Comments
 
LVL 6

Expert Comment

by:gjohnson99
ID: 12550523
Why not use a dns server  ?
0
 

Author Comment

by:AZEMBB
ID: 12550598
DNS would have been nice, but the desktops are spread out worldwide on various networks and domains which are not able to be administered.
0
 
LVL 5

Accepted Solution

by:
SKULLS_Hawk earned 2000 total points
ID: 12553162
http://www.ntmag.com/WindowsScripting/Article/ArticleID/8187/8187.html

Try this link, it deals with exactly what you want.  It has a download with pre scripted files in, and instructions on how to configure.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us in IT utilize a combination of roaming profiles and folder redirection to ensure user information carries over from one workstation to another; in my environment, it was to enable virtualization without needing a separate desktop for each…
We recently endured a series of broadcast storms that caused our ISP to shut us down for brief periods of time. After going through a multitude of tests, we determined that the issue was related to Intel NIC drivers on some new HP desktop computers …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Loops Section Overview
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question