How to Fix Access is Denied While Editing Hosts File

In this post you will see:

  • How to fix access is denied error while editing the hosts file
  • How to reset the hosts file to default

Let’s start.

Note: The hosts file is in C: > Windows > System32 > drivers > etc.

How to fix access is denied while editing the hosts file

The “Access is denied” error occurs when opening, saving, or editing the hosts file that is a system file in Windows 10.

Let’s look at the four methods to fix this bug. Select the one you want.

Method #1

Start the Notepad app as an administrator.

Press File > Open.

Go to this location – C: > Windows > System32 > drivers > etc.

Open the drop-down list above the “Open” button and select “All Files.”

Select the “hosts” file.

Click on the “Open” button.

Notes:

If you are not using Notepad, open the text editor program you are using as an administrator, and then open the “hosts” file in it.

If you are still having problems, make sure that the “hosts” file is not read-only.

Here’s how you can do it:

Right-click on the “hosts” file.

Click on “Properties.”

See “Read-only” in the pop-up.

If it is not selected, close the popup. Otherwise, remove the selection and press the “Ok” button.

Read: How to show hidden files in Windows 10

Method #2

Start the command prompt with administrator privileges.

Enter the following command and then press the “Enter” key.

Here is the command: cd c:\windows\system32\drivers\etc

Enter the following command and then press the “Enter” key.

Here is the command: notepad hosts

Note:

If you are still having problems, make sure that the “hosts” file is not read-only. Here’s how you can do it:

Right-click on the “hosts” file.

Click on “Properties.”

See “Read-only” in the pop-up.

If it is not selected, close the popup. Otherwise, remove the selection and press the “Ok” button.

Read: How to change DNS server in Windows 10

Method #3

Copy the “hosts” file to the desktop.

Once you have finished the work and saved the file, cut or copy the “hosts” file on the desktop and paste it into the “etc” folder in C: > Windows > System32 > drivers.

In the pop-up, hit “Replace the file in the destination.”

Click on “Continue.”

Read: How to restart the File Explorer

Method #4

Open the elevated command prompt.

Enter the following command and press Enter:

net user administrator /active:yes

The above command activates the hidden administrator account.

Now, you need to log in to the “Administrator” account you have activated.

Access the hosts file.

Once you are done with the file, sign in to your user account and then disable the hidden admin account.

Here is how:

Open the elevated command prompt.

Enter this command and press Enter:

net user administrator /active:no

That’s it.

Read: How to open Programs and Features

How to reset the hosts file to default

Here is how you can reset the hosts file:

Open Notepad.

Copy and paste the following into the Notepad file:

# Copyright (c) 1993-2009 Microsoft Corp.

#

# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.

#

# This file contains the mappings of IP addresses to host names. Each

# entry should be kept on an individual line. The IP address should

# be placed in the first column followed by the corresponding host name.

# The IP address and the host name should be separated by at least one

# space.

#

# Additionally, comments (such as these) may be inserted on individual

# lines or following the machine name denoted by a ‘#’ symbol.

#

# For example:

#

# 102.54.94.97 rhino.acme.com # source server

# 38.25.63.10 x.acme.com # x client host

# localhost name resolution is handled within DNS itself.

# 127.0.0.1 localhost

# ::1 localhost

Press Ctrl + S. In the popup, specify the following filename: “hosts”

Make sure you have entered the filename with quotation marks as above.

Press the Save button.

Copy or cut the hosts file you have created.

Now go to C: > Windows > System32 > drivers > etc folder.

Change the name of the hosts file as hosts.bak. Hit Continue. Hit Yes.

Paste the previously copied or cropped file into the etc folder. Hit Continue.

That’s all.

Read: