Question

I've been trying to edit my host file for a while now and I keep failing. I tried to open notepad as administrator and then click File --> Open and choosing the host file but I get this error message:

hosts

You don't have permission to open this file.

Contact the file owner or an administrator to obtain permission.

I tried notepad++ as well (as administrator) but I couldn't even get to the file with it (it doesn't show the etc folder in drivers). I also tried to check my "User Account Control Settings" but it was already on the lowest level (never notify). While looking online for a solution I've noticed more people having the same problem but I couldn't find a solution that worked for me.

I'm running Windows 7 Home Premium 64-bit

Was it helpful?

Solution 7

OK I got it! I had to right click the file, go to Properties, Security tab and click Edit. Then I took ownership for the file and I had the ability to edit the file's permissions.

OTHER TIPS

You have to run notepad++ (or your favorite text editor) as an administrator. Right click notepad++ and it should display an option to run it as admin. Once open, locate the hosts file and open it with notepad++.

Windows hosts file location: c:\windows\system32\drivers\etc

Note: copy and paste the above url in the file-explorer when opening a file within notepad++ instead of locating it manually as some directories are hidden.

If the above doesn't work, Windows 10, 8 sometimes requires you to first turn off your antivirus.


If you require editing the hosts file often, you could look into third-party freeware tools to aid you. [1][2]

This works: For Windows 7 and Windows Vista

Click Start -> All Programs -> Accessories. Right click on Notepad and select Run as administrator. Click Continue on the "Windows needs your permission" UAC window. When Notepad opens Click File -> Open. In the filename field type the file location, i.e.:

C:\Windows\System32\Drivers\etc\hosts

Click Open. Make the necessary changes to the hosts file. Click File -> Save to save your changes.

In my case I could open the file (and Notepad++ was running as admin) however I could not edit it: I could neither type some text, nor delete anything - no popups, no warnings - it looked like keyboard is not working.

I copied the hosts file in the same location, deleted the original hosts file and renamed the new one to hosts. After that I was able to edit the file. I am guessing this should be some permission issue.

OS - windows 7

But first of all you have to do temporally disable your virus guard.

Dissable your antivirus and open notepad.exe with run as administrator edit your host file and save this.

'Run as admin' not enough in windows 8. Set 'modify' access also not enough if you have antivirus

So you need

1) Disable antivirus

2) Set 'modify' access for all applications

3) Modify 'hosts' file

4) Revert 1-2 steps

On windows 8 running notepad as administrator wasn't enough for me to edit this file. When I tried to open the file from within an administrator session of notepad the etc directory was empty. I changing explorer to show hidden files and extensions, but that only helped in explorer. To edit this with notepad I needed to modify the security settings on the file so that all users and all applications could write to the file. After I finished my changes I set the file back to read only and execute for all applications and users.

there are two notepad.exe in x64 windows,

you must use full path c:\windows\system2\notepad.exe ,this one is 64 bit version,

only type notepad whithout path may be launch 32 bit notepad. (c:\windows\syswow64\notepad.exe)

"Run as administrator" just let you enforce launch 64 bit notepad.exe

using 32 bit software to edit c:\windows\system32\drivers\etc\hosts

the x64 system will automatic redirect to c:\windows\syswow64\drivers\etc

and there is no hosts file.

the GUI stiil display current folder is c:\windows\system32

but the real folder is c:\windows\syswow64

I had the same problem. After opening the notepad as an Administrator and editing hosts file, I could not save it (denied access). I could not even change file's permissions. What worked for me was copying the file elsewhere, editing there, and then overwriting the original through Command Prompt opened as Administrator. I didn't have to turn off antivirus program.

To open the Command Prompt as administrator, press windows+X and select that option from the menu.

Than, type: mv path-to-the-copy-of-hosts-file\hosts c:\windows\system32\drivers\etc\hosts

I just needed to uncheck "read only" property to allow modify that file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top