Windows 7 hosts file: “access denied”

Win7.png Some people might have problem to edit their hosts file on Windows 7. A very common problem is that the error message “access denied” pops up. To solve this little problem, here’s a brief instruction how to take ownership of that file and edit it.


If you are on Windows 8 and receive this error, you should also read this guide

UPDATE: The fastest way to modify the hosts file in Windows 7 if you get the access denied error is this:
1. Step Open an elevated command prompt as described here: Elevated cmd.exe
2. Step Enter cd \windows\system32\drivers\etc
3. Step Enter notepad hosts – Or simply open an elevated notepad instance.

If you are not familiar with the command prompt, you can follow the old slow tips below.

Hosts File: Access Denied Error Messages

Here are the error messages you may receive:

You don’t have permission to save in this location. Contact the administrator to obtain permission. Would you like to save in My Documents folder instead?
Access to C:\Windows\System32\drivers\etc\ hosts was denied
Cannot create the C:\Windows\System32\drivers\etc\hosts file.
Make sure that the path and file name are correct.

Windows 7 does not give the average user access to many system files. The hosts file is one of those system files.

What can you do about it? First of all, you should know that the default account is not *the* admin account. Therefore, I’d recommend to activate the administrator account to modify system files.

1. Quick workaround to edit the hosts file

You can also simply create a copy of the hosts file. Right-click – “Copy here” and then modify it. Then delete the real hosts file and rename the copy that we just created to “hosts”.

2. Activate Hidden Admin Account

Goto “Start” and enter “cmd” into the search field. Hold CTRL + Shift and hit Enter to run cmd.exe as an administrator.
Enter the following line:
net user administrator /active:yes

Take Ownership

3. Take Ownership of the hosts file

Instead of activating the admin account, you can simply add a little option “take ownership of this file” to the context menu.

Simply download the following zip file that includes two registry files. One to add this option to the contect menu and one to remove it.

Download TakeOwnership.zip

Alternatively, you can simply copy and paste the following text into a text file and rename the extension to “.reg” (for registry) and then execute it.

[HKEY_CLASSES_ROOT\*\shell\runas]
@="Take Ownership"
"NoWorkingDirectory"=""
[HKEY_CLASSES_ROOT\*\shell\runas\command]
@="cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F"
"IsolatedCommand"="cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F"
[HKEY_CLASSES_ROOT\Directory\shell\runas]
@="Take Ownership"
"NoWorkingDirectory"=""
[HKEY_CLASSES_ROOT\Directory\shell\runas\command]
@="cmd.exe /c takeown /f \"%1\" /r /d y && icacls \"%1\" /grant administrators:F /t"
"IsolatedCommand"="cmd.exe /c takeown /f \"%1\" /r /d y && icacls \"%1\" /grant administrators:F /t"

5 of 5 0 (100%) 1 vote
- Cheers!

Tags:


Written by:
Oliver is the founder and lead editor of this site. He is interested in finding new ways to break Windows, find common errors and help others to fix them. Aside from that, he loves to fully customize systems with Rainmeter and Dreamscene, find out more about ancient civilizations like the Chachapoya, sharpen his digital photography skills and create software with a small group of selected developers. If you would like to connect with him to discuss anything, send him a mail!

Learn More About.Me

Follow me on Twitter for daily updates: Twitter Follower

Contact The Author:
support@windows7themes.net

Get Free Help

Connect With Our Site:

 

   


Need help? Ask a question at our QA site, click the red button to get started:
Want to support us? Great, simply buy your favorite games from G2A via our referral link (g2a.com/r/win7themes) and save money at the same time:

27 Responses to Windows 7 hosts file: “access denied”

  1. Orange Community Approved Comment:
    Robert said:

    You should NOT have to take ownership of the file. Do this.

    Open an administrator command prompt (look above for the trick)
    Type: cd \windows\system32\drivers\etc
    Type: notepad hosts

    Make your changes and save. I never had to take ownership of the file. It remains owned by SYSTEM like it should be.

  2. Orange Community Approved Comment:
    luttis said:

    1. Click Start–>All Programs–>Accessories–>Notepad–>Run as administrator.

    2. Go to open, host location and open. Edit and save. Sorted.

  3. Orange Community Approved Comment:
    adrian said:

    hello, i baught a new computer a couple of weeks ago i was so excited windows 7 on it already installed i made a new user for my brother to use.
    recently i tried to connect to get some files from my dads computer via the network in “computer”. access denied.
    i cant install anything i need the computer administrator.. but how i have 2 user accounts log on both of them the orginal all of them … no still not please some1 help ?

  4. Orange Community Approved Comment:
    sOliver said:

    adrian I am not sure if I understand you correctly, are you trying to access the PC of your dad via the network, but it doesn’t work?

    Make sure that you disable all firewalls. If you want to install something on the PC of your dad via the network, you will need to establish a remote desktop session. You can either use the built-in Windows remote desktop or if you are on Windows 7 Home Premium, you might need UltraVNC http://windows7themes.net/remote-desktop-host-for-windows-7-home-premium.html

    I would recommend to access the PC of your dad directly and then install whatever you want. Sometimes you will need access to the administrator account in Windows 7, if you don’t know how to activate it: http://windows7themes.net/how-to-login-as-administrator-in-windows-7.html

  5. Orange Community Approved Comment:
    bob said:

    windows 7 was NOT my idea. my ex-wife’s idea maybe (but that’s a different post altogether).

    all i want to do is run a command as administrator in a command file. apparently, there isn’t a way to do this. i must use the GUI to run the command file (selecting RUN AS ADMINISTRATOR), which defeats the whole point of the command file. anybody know how, from an existing non-administrator command prompt, to run a command as administrator? (this is on-topic because the command i want to run is “notepad c:\windows\system32\drivers\etc\hosts”)

  6. Orange Community Approved Comment:
    sOliver said:

    bob do you know the runas command? Here’s an example if you want to start a new command prompt as admin:

    runas /u: Administrator cmd.exe

    This will work in a different way in a command file, but I’ll have to look into that now. Maybe this will already get you going for now. Enter runas into a command prompt and you will get some additional help.

  7. Orange Community Approved Comment:
    Diamond Dave said:

    Luttis on 11-22-09′s option works for sure in Windows 7.

  8. Orange Community Approved Comment:
    mars said:

    I did everything what was shown but still access denied what next?

  9. Orange Community Approved Comment:
    zulu said:

    mars,

    you didn’t do it correctly, or it would have worked. every one of those solutions work.

  10. Orange Community Approved Comment:
    T said:

    I did everything to the letter also and still no access

  11. Orange Community Approved Comment:
    sOliver said:

    T, please read the first two comments. You don’t have to take ownership of the file.

    Open an elevated command prompt as described here:
    Elevated cmd.exe

    then..
    Type: cd \windows\system32\drivers\etc
    Type: notepad hosts

    Edit the file and save. Done!

  12. Orange Community Approved Comment:
    Lenin said:

    I tried all these and failed exceptind the advise that Luttis gave here. It worked fine for me Im runnig windows 7 Ultimate edition .Thank you!! :-)

  13. Orange Community Approved Comment:
    Iquit said:

    XP was to user friendly, fast and easy to use.
    I wanted more awkward and slower software for IT professionals forced to develop for Windoze based customers.
    I am a slug and Windows 7 was my idea (Vista was Brian the snails prototype).

  14. Orange Community Approved Comment:
    sOliver said:

    Iquit (lol), XP was also a lot less secure. Microsoft had to add the UAC for security reasons. If you’d prefer an insecure system, then go with XP. Also, with a little bit patience you will have no problems editing the hosts file as described above without access denied errors.

    I also updated the post for you to make it really easy. Should be doable :)

  15. Orange Community Approved Comment:
    Fiat_bm said:

    Guys,

    I’m trying to sort a problem out for a friend who has a redirect virus (spybot has identified it, but can’t remove it) on Windows 7 x64.

    When I navigate to the folder (using explorer or cmd) C:\WINDOWS\system32\drivers\etc the hosts file is missing (hidden files are set to display in folder options).

    So I try to create a fresh, basic copy using the text from Windows support site and by selecting notepad to run as admin. When I try to save the file I get an error saying the hosts file exists would you like to overwrite, select yes. Next error says hosts file marked to read only please save file with a different name. I have altered spybot so that it doesn’t lock the host file and tried the above again, no luck.

    I’ve also tried…
    AVG 2011, which wouldn’t open.
    Avast, didn’t find it.
    Hitmanpro, seemed to find other stuff and deleted them.

    Pretty sure the problem can be corrected by reseting the hosts file, but the only way I can get windows 7 to acknowledge the file exists is by trying to create a fresh one.

    Any ideas would be greatly appreciated.

  16. Orange Community Approved Comment:
    Mark said:

    I had the same issue while trying to clean out an mal/spyware infected machine. I ran elevated CMD and NOTEPAD prompts to no avail. Tried the W7 Repair Disc, Safe Mode Command Prompt, etc. Nothing.

    The HOSTS file was also Hidden/System/ReadOnly. You will have to change your “View” settings to show hidden files, show protected files.

    My solution was easy, right-clicked the HOSTS file, click the SECURITY tab and “Authenticated Users” was the only thing on the list. Problem was it was “Read Only” permissions, clicked Full and applied and everything was good to go. Edited the file and it was fixed.

    The HOSTS file was redirecting common sites to 74.54.xxx.xxx rather than the standard:
    127.0.0.1 localhost

    Hope this helps someone…

  17. Orange Community Approved Comment:
    Allan Elder said:

    I was just going through this after removing one of those browser hijacks from my wifes machine; I’m an IT veteran of 20 years and it took me hours to get past this.

    What I had to do to get it to work was….

    1. Make hidden files visible (the hijack had made hosts read only and hidden).

    2. Open Explorer as administrator, right click on hosts, go to the security tab. You’ll see that even the administrator group has only read access to the file thanks to the Hijack. Click on Edit, and give the administrator group full control.

    3. Now you can open Notepad as administrator and edit / save the file.

  18. Orange Community Approved Comment:
    sOliver said:

    Allan, sorry no offense but I can’t believe you are an IT veteran or at least you don’t know much about Windows 7.

    Windows Vista and Windows 7 both have a very secure permission system. The system is highly complicated for beginners, but it’s secure. Do you even know about UAC?

    1. You are correct, by default the hosts file is visible. So it WAS a hijack that hide the hosts file so you couldn’t access it.

    2. Wrong, you need admin rights (either elevated cmd or elevated notepad) this is NOT a hijack problem, but intended by Vista and Windows 7 for security reasons.

    3. I usually do it like this. Open elevated cmd (see our tutorials) then enter “cd drivers/etc” then enter “notepad.exe hosts” without the quotes and it will open an instance of the notepad with admin rights and I can edit the hosts file without getting the access denied error.

    I learned a lot about Windows 7 while messing around with themes, but this is basic knowledge.

    Anyway, if you guys still get hosts file access denied error, post your problems and I will try to help, that’s all I can do.

  19. Orange Community Approved Comment:
    Allan Elder said:

    sOliver

    Please re-read what I wrote in pt 2; I HAD elevated access rights (including in a previous attempt doing what you described in your 3rd point); but the Hijack had altered security on the file, not just the attributes, so that the Administrator only had read privs. I’m fairly certain that the hijack had altered security on the file, not sure what else could have done it. EMET is on that machine, but shouldn’t be touching the hosts file.

    This is a fairly new Hijack that is doing this I think, there seems to be alot of people on the malwrebytes forums with the same issue. I registered there to try and post to see if someone could confirm but don’t seem to be allowed to post :|

  20. Orange Community Approved Comment:
    Ali said:

    Hi……
    In my office. i want to block orkut through (“notepad c:\windows\system32\drivers\etc\hosts”) host file. but if i want to save host file.
    The Error msg display : “You dont have permission to save this location. contact your administrator.” But i am also Login through Administrator.
    Please Help me..
    Details : I have a Windows 7.

  21. Orange Community Approved Comment:
    sOliver said:

    Ali, you will always get that permission error when you don’t open the hosts file elevated rights.

    Open an elevated command prompt as described above in the comments

    Type: cd \windows\system32\drivers\etc
    Type: notepad hosts

    Then you will not get the access denied error, nor any permission errors.

  22. Orange Community Approved Comment:
    Mayank said:

    hey pls help for my windows 7 i tried to replace .ini in odeon folder for jaf but it says access denied pls help me wht should i do?

  23. Orange Community Approved Comment:
    sOliver said:

    Mayank, you need to take ownership of that ini file you want to replace please read our many tutorials for a how to

  24. Orange Community Approved Comment:
    Mayank said:

    arrey but how i tried all of tht stuff it say’s

    an error occurred while applying security information to:

    c:\program files\odeon\jaf

    Access is denied.

    pls pls pls help me?

  25. Orange Community Approved Comment:
    InIT-UK said:

    Hi.

    One other thing you may wish to check is your Security Software be it Anti Virus etc.

    McAfee as an example in a corporate environment has an option to “Block Changes to your network settings” this covers and includes the hosts file.

    No matter what you do at a permission level you will still recieve access denied messages and you require permission from messages.

    May be of help to some.

  26. Orange Community Approved Comment:
    ruben said:

    this is bull. i keep trying to save this file but it saves it as a text file. i am running cmd elevated and type in notepad.exe hosts and when i add the lines i want and try to save it saves it to my desktop but it isn’t editing or save the host file that it is hidden in the drivers\etc\hosts.

  27. Orange Community Approved Comment:
    Syed Shah said:

    Follow Simple steps
    open file explorer and type C:\Windows
    scroll down and select notepad.exe and left click and then click on ‘Run as administrator’ when notepad is open
    click on File from top menu then click open or press CTRL + o
    paste C:\Windows\System32\drivers\etc and select all from the right combo box
    choose the file and after update save it.

    Please try and reply if its work
    Its working for me I am using Windows 8, and I tested on Windows 7

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Current day month ye@r *