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
ID: 17912889
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
ID: 17912900
You can use \n characters

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

Expert Comment

ID: 17913009
if this is dos, you may need
echo. >>  "%systemroot%\system32\drivers\etc\hosts"

Assisted Solution

JRockSolid earned 41 total points
ID: 17921353
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

ID: 17958477
Any Luck YEO?

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

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…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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 …

803 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