5 Ways To Modify Windows Hosts File: “Access Denied” (2015 Update)

Win7.png 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

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:

Run Notepad Plus Plus As Administrator.png

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

Method 4: Activate Hidden Windows Admin Account

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

Take Ownership

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.

@="Take Ownership"
@="cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F"
"IsolatedCommand"="cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F"
@="Take Ownership"
@="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.
Published: Thursday, October 1st, 2015 Last Modified: October 1, 2015