Editing the hosts file on Windows Vista

Posted in Windows -

On Windows Vista the hosts file has a higher level of default security than earlier versions of Windows and it cannot be edited by a regular user unless the permissions are changed, or you run your text editor as administrator. This post looks at how to edit the hosts file on Windows Vista using notepad.

What is the hosts file?

The hosts file contains a list of IP address to hostname mappings and can be useful especially for web developers if they need to point a hostname to a specific IP address while developing or testing a website, without having to change settings on a DNS server. On Linux and Unix systems it is typically at /etc/hosts and on Windows systems (Windows 2000, XP, Vista) at c:\windows\system32\drivers\etc\hosts

Error message when editing the hosts file on Windows Vista

If you open the hosts file on Windows Vista and then attempt to save it as a regular user, you will get an error message as show in the screenshot below ("Cannot create the c:\windows\system32\drivers\etc\hosts file. Make sure that the path and file name are correct):

cannot create hosts file error

The reason for the error message is not that it cannot be created, but that you do not have sufficient permissions to write to that file.

Running notepad as administrator

The solution to this error is to run notepad (or other editor) as administrator and you will then be able to save the hosts file with no issues. To do this, locate the "Notepad" program on the start menu (it's under "All Programs" then the "Accessories" folder. Right click the "Notepad" icon and select the "Run as administrator option as shown in the screenshot below.

running notepad as administrator

The user account control dialog will then pop up and ask you if you want to run notepad as administrator. I can't do a screenshot of this, but click the "Continue" button and then notepad will start. You can then edit and save the hosts file with no issues. 

Locating the Windows hosts file

The Windows hosts file is at c:\windows\system32\drivers\etc\hosts, and you can simply type this in (or copy and paste from this page) when you go into the the open dialog using the Ctrl+O shortcut. You can also navigate to c:\windows\system32\drivers\etc as shown in the screenshot below. Initially it will say "no items match your search" but this is only because it's trying to show only files with a .txt extension. Open up the files type drop down box and select "All files". This is shown opened up in the screenshot below bottom right.

search for notepad

Conclusion

Microsoft have tightened up the security of the hosts file on Windows Vista by making it only editable by the administrator by default. It's still easy to edit the file, however, by simply running the notepad (or other text editor) as administrator.



Related posts:


Comments