Computing.Net > Forums > Programming > Dos Bat. to edit file (hosts)

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Dos Bat. to edit file (hosts)

Reply to Message Icon

Name: mikesoong
Date: July 27, 2006 at 03:57:09 Pacific
OS: XP
CPU/Ram: 256
Product: hp
Comment:

How do I write a dos bat file to edit my hosts windows file.
Currently I have written a login script that every time a user login it will append "172.29.1.43" to hosts file by using the following command echo 172.29.1.43 >>hosts. But the problem append will keep on writting new 172.29.1.43 to the end of other line.
My intention here is every time a user login ... it will append 172.29.1.43 to hosts file but if the 172.29.1.43 exists then it will only overwrite the IP.



Sponsored Link
Ads by Google

Response Number 1
Name: Shr0Om
Date: July 27, 2006 at 07:31:43 Pacific
Reply:

Well, this wont overwrite anything, but just not add the ip to hosts since its already in there (dunno if that works for you)

type hosts |find "172.29.1.43"
if errorlevel 1 (echo 172.29.1.43>>hosts) else exit

Now i assume that you use a variable containing the ip?.. If so replace 172.29.. with the %variable%



0

Response Number 2
Name: mikesoong
Date: July 27, 2006 at 09:21:57 Pacific
Reply:

thank you it works


0

Response Number 3
Name: Shr0Om
Date: July 27, 2006 at 12:00:39 Pacific
Reply:

No problem:)


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Dos Bat. to edit file (hosts)

Batch file to edit text file www.computing.net/answers/programming/batch-file-to-edit-text-file/19329.html

Dos Batch to compare file times www.computing.net/answers/programming/dos-batch-to-compare-file-times/17476.html

How to edit a .bat file or text file?? www.computing.net/answers/programming/how-to-edit-a-bat-file-or-text-file/2682.html