Solved

batch file to replace string in the hosts file

Posted on 2007-11-14
6
1,474 Views
Last Modified: 2012-06-27
I need to create a batch file that will find and replace a sting in the hosts file on nt workstation 4.0.  For example, I want the batch file to find the line :-

server1    182.168.1.2

and replace it with

server1   182.168.1.34

I am used to writing vbs scripts but don't want to use vbs as I would need to install the run time engine.  Is there a way of doing it cmd batch files?
0
Comment
Question by:anternieTS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
6 Comments
 
LVL 4

Expert Comment

by:512Thz
ID: 20285826
@echo off
find /V "192.168.1.2" < lmhosts > temp.tmp
echo server1 192.168.1.34 >> temp.tmp
ren lmhosts *.bak
ren temp.tmp lmhosts
0
 
LVL 4

Accepted Solution

by:
512Thz earned 250 total points
ID: 20289352
A better solution (it sends the "server1" entry on top of file (which is recommended)
NOTE. the file might be named "hosts" instead of "lmhosts"
_______________________
@echo off
if exist hosts.bak del hosts.bak
ren hosts hosts.bak
echo server1 192.168.1.34 > hosts
find /V "192.168.1.2" < hosts.bak >> hosts
_______________________

btw You normally do'nt have to install a run time to execute a VBS what OS are you running?
0
 

Expert Comment

by:Jameshontishar
ID: 20314819
Are you using this in a domani, if so use a batch file associated to a GPO
0
 
LVL 4

Expert Comment

by:512Thz
ID: 20330751
I think I answered the question. Please accept it or tell us what's wrong
0
 
LVL 1

Expert Comment

by:Computer101
ID: 20521562
Forced accept.

Computer101
EE Admin
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you considered what group policies are backwards and forwards compatible? Windows Active Directory servers and clients use group policy templates to deploy sets of policies within your domain. But, there is a catch to deploying policies. The…
Background Information Recently I have fixed file server permission issues for one of my client. The client has 1800 users and one Windows Server 2008 R2 domain joined file server with 12 TB of data, 250+ shared folders and the folder structure i…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

726 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