Adding a sentence to host file.

Posted on 2006-11-10
Last Modified: 2010-04-16
Hello All, i wish to know how to add a sentence to host file using the batch file.

echo localhost >> "%systemroot%\system32\drivers\etc\hosts"

But everytime i double click this batch file. Instead of going to the next sentence of the host file, it will just add next to the last line of the host file. example:-

xx.xx.xx.xx After i double click the host file above it will become:-

xx.xx.xx.xx localhost

But i want the localhost to be at the next sentence. Isst possible?

Please advice me.

Question by:YeoBoonWah
  • 2
  • 2
LVL 84

Accepted Solution

ozo earned 43 total points
Comment Utility
echo >>  "%systemroot%\system32\drivers\etc\hosts"
echo localhost >> "%systemroot%\system32\drivers\etc\hosts"
LVL 19

Assisted Solution

by:Albert Van Halen
Albert Van Halen earned 41 total points
Comment Utility
You can use \n characters

IE echo "\n127.0.0.1 localhost" >> "%systemroot%\system32\drivers\etc\hosts"
LVL 84

Expert Comment

Comment Utility
if this is dos, you may need
echo. >>  "%systemroot%\system32\drivers\etc\hosts"

Assisted Solution

JRockSolid earned 41 total points
Comment Utility
Make sure your cursor i on an empty line in your host file then save it  EXAMPLE

1 localhost
2 localhost
3 localhost
4 localhost
5 localhost
6  |<<<<Cursor here and save
now try it

Expert Comment

Comment Utility
Any Luck YEO?

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
scores100 challenge 3 82
strCount chalenge 3 50
Counting documents in a Domino View 3 31
Adoquery sql  left join does not work 25 38
Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now