Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

batch file to replace string in the hosts file

Posted on 2007-11-14
6
Medium Priority
?
1,479 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 1000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

The password reset disk is often mentioned as the best solution to deal with the lost Windows password problem. In Windows 2008, 7, Vista and XP, a password reset disk can be easily created. But besides Windows 7/Vista/XP, Windows Server 2008 and ot…
Know what services you can and cannot, should and should not combine on your server.
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…

618 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