Modifying Your Vista Hosts File in Just Six Steps
I guess some bad things can happen if a hosts file is changed without the user's knoweledge. However, the number of steps required to do this on Windows Vista is a little over the top and cost me some valuable time this morning.
Before we go through the Vista steps, lets take a look at how you did this in previous versions of Windows and OS X.
Windows XP and Windows 2003
- Navigate to Windows > System32 > Drivers > etc
- Open the file (with no extension) hosts
- Make your changes and save the file.
OS X
- Navigate to /etc
- Open hosts (no extension) in your favorite editor (TextMate for me)
- Make your changes and save the file.
- OS X will then ask you for an administrator password before saving the file
Widows Vista
- Navigate to Windows > System32 > Drivers > etc
- Make a copy of this file and paste it some where else since you are no longer allowed to directly edit the file (I am guessing you could do a save as in step 3 as well)
- Open the file, make your changes, and save the file.
- Make a copy of your updated file and paste it over the original which brings up the new Vista copy dialog

- Next, you are warned that you need to be an administrator to make this change.

- Finally, you get to the UAC screen which again requires the same confirmation as the previous step.

There are three steps in Windows XP and Window 2003 and a fourth in OS X. In an effort to add the fourth (security) step to Vista, they have added an additional 3 steps (4 if you count the fact you may need to restart your browser to see the changes).
We are not talking about a lot of extra work here, but IMO, this is complication for complication sake. Why not just show the UAC message when I try to save the file? Why show a dialog before UAC which essentially tells me the warns me about same thing UAC is warning me about?
I spent way too much time trying to get this to work early this morning, so hopefully this little rant helps someone else out in the future and is a reminder to everyone who designs software to remember even if they are simple steps, less is always better.


Comments
Scott on on 1.14.2008 at 12:43 PM
I've found it easiest to do this:
1) Open notepad ("Run as administrator")
2) Within notepad use the open dialog to find the host file
3) Edit and save.
You will still get the annoying UAC dialog when you run notepad as administrator but that is the only one you will see. Of course, IMO the best thing you can do is to turn UAC off since it is about worthless anyway.
Scott Watermasysk on on 1.14.2008 at 12:57 PM
@Scott
Good tip, I should have remembered that.
Chad Myers on on 1.14.2008 at 1:07 PM
1.) WinKey, notepad, CTRL+ENTER
2.) ALT+C to confirm UAC pop-up
3.) CTRL+O, c:\windows\system32\drivers\etc\hosts, ENTER
4.) CTRL+S, ALT+F4
John S. on on 1.14.2008 at 4:01 PM
XP has the browser restart issue too if you're using IE since it caches DNS for the browser session.
Rick Reszler on on 1.14.2008 at 7:29 PM
You can also just open notepad as administrator and then open the file and edit it. This is very similar to most Linux OS's out there today.
Josh Ledgard on on 1.14.2008 at 9:11 PM
I sort of go with Rick's mode. I have a cmd.exe shortcut that opens it in admin mode after a UAC promt. So then any app or command I run from that windows runs with admin rights. In this case I just notepad open the file and it saves fine. More than one way to skin a cat. :-)
c.sokun on on 1.15.2008 at 9:28 PM
Didn't you guy turn off UAC on your first login to Vista?
It my rule not Vista
C M on on 1.19.2008 at 5:56 PM
Turning UAC it's in fact a necessity. Otherwise we are popped up for everything.
Chad Myers on on 1.26.2008 at 9:54 AM
Actually, when changing the hosts file, any active processes which has queried that hostname (if you're changing one), will need to be restarted since the Windows DNS resolution stuff caches the IP in the process's memory space.
IE, FireFox, even ftp.exe are affected.
I believe that if you ADD a new host to your hosts file, you're OK (no app restart required). I'm not sure, but I *think* that if you modify a host that hasn't been queried yet by the app, you're OK also (because an attempt hasn't been made to resolve that host yet, so it's still 'new' to that app instance)