Some people might have problems editing their hosts file on Windows. A very common problem is that the error message “access denied” pops up. To solve this little problem, here are 5 ways to modify it.
If you are on Windows 8 and receive this error, you should also read this guide
Step | Link |
---|---|
1 | Quickest Method To Change Hosts File |
2 | Use An Elevated Notepad |
3 | Delete Hosts File / Re-create It |
4 | Use Hidden Windows Admin Account |
5 | Take Ownership Of It |
Method 1: Fast Solution To Modify It
UPDATE: The fastest way to modify the hosts file in Windows 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.
Method 2: Modify Hosts File Using An Elevated Notepad++ Instance
1. Step Download the program notepad++
2. Step Locate the installation directory and start the program with elevated admin rights (right-click on notepad++.exe and select Run as Administrator). Alternatively, simply search for it and right-click on it:
3. Step You will be asked to confirm the UAC prompt to allow notepad++.exe to run with elevated rights
4. Step Open C:\Windows\System32\drivers\etc in a Windows Explorer window
5. Step Drag the hosts file into your notepad editor. You can now hopefully write and save the Windows hosts file directly without further problems
Method 3: 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”.
Before you can delete the hosts file you may have to take ownership of it.
The following script will help you with that
Windows does not give the average user access to many system files. The hosts file is one of those system files.
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.
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
Method 5: 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.
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"
Hosts File: Access Denied – Common 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.
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.
1. Click Start–>All Programs–>Accessories–>Notepad–>Run as administrator.
2. Go to open, host location and open. Edit and save. Sorted.
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 ?
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
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”)
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.
Luttis on 11-22-09’s option works for sure in Windows 7.
I did everything what was shown but still access denied what next?
mars,
you didn’t do it correctly, or it would have worked. every one of those solutions work.
I did everything to the letter also and still no access
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!
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!! :-)
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).
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 :)
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.
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…
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.
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.
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 :|
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.
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.
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?
Mayank, you need to take ownership of that ini file you want to replace please read our many tutorials for a how to
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?
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.
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.
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