by Oliver
26. January 2011 20:30
Today: a simple hosts file editor
Today I set up a new project on GitHub: the Teamaton tool belt! It shall serve us as a central store for small tools, probably mostly command-line, built for a single purpose. The first tool in our new tool belt is: HostsEditor.
I wrote this small command line utility after reading this blog post: http://apdubey.blogspot.com/2008/09/edit-host-file-by-batch-file.html. We were looking for an easy way to edit the Windows hosts file from a script for a larger development environment setup that we wanted to fully automate including IIS website, bindings and new entries in the said hosts file. Of course, for a one-timer echo does the job, but don’t try to run the setup script twice on the same maching – you’ll get duplicate entries very quickly.
Reading about how other people are asking the author of the above post how to avoid the duplicates or how to erase entries from the hosts file, I set out to simply write such a utility myself and share it with the rest of the world. If there is one other person out there to whom it will be useful I will be happy.
So, HostsEditor does the following:
- Adds and removes entries to and from the Windows hosts file.
- Automatically backs up the original hosts file to hosts.bck.
- Does not add duplicate entries; instead prints a warning.
- For usage in automation scripts there is /q switch to suppress all info messages.
That’s all there is to it for now. But there’s more to come!
Stay tuned, Oliver