ACTIVE MALWARE WINDOWS TESTED: WINDOWS XP

How to fix
Notepad “Access Denied” when editing Hosts file
on Windows

Easily resolve the "Access Denied" error when editing the Hosts file on Windows 10 or Windows 11. Expert-tested methods for quick fixes.

How to fix Notepad “Access Denied” when editing Hosts file on Windows?
Quick Summary
Error severity
Medium
Est. time
35 minutes
Offer Fortect PC Suite
Start fix →
Ad · we may earn a commission
0 Comments
01

What causes How to fix Notepad “Access Denied” when editing Hosts file on Windows?

  • User does not have permission to edit the Hosts file
  • Hosts file is hidden and not visible
  • Windows OS restricts access to the Hosts file
  • Ransomware may have modified the Hosts file
  • File may be in use by another application
Offer Fortect PC Suite

Repairs Windows system files, removes malware, and restores a clean OS state — without reinstalling.

Ad · we may earn a commission
Get Fortect PC Suite ↗

I was recently infected with ransomware, and I read on the instructions online that I need to modify the file in order to regain normal internet access. After I edit it and try to save it, however, it returns an error "Access denied." Any idea how to bypass that? Thanks.

Hosts file is a simple text file located inside C:\\Windows\\System32\\drivers\\etc\\ folder on Windows XP, 7, 8, and 10 operating systems. In some cases, it might be hidden, so users might not immediately see it, as they would have to enable the "View hidden items" feature via File Explorer. Essentially, Hosts file was used for Name to IP address resolution, although modern DNS[ref en-1] features quickly replaced it.

However, Hosts file still manages to find various uses in modern times, and is especially useful for people from the IT field, such as web developers or networking administrators, as they can develop websites locally or filer various content.

Unfortunately, the Hosts file can also be abused by cybercriminals to prevent users from accessing specific websites (for example, Djvu ransomware[ref en-2] is known to use this feature to stop victims from visiting sites that would help them with malware removal or file retrieval process). In such a case, users might want to edit the Hosts file to bypass these malware-set restrictions.

Access denied error
Access denied error

However, many users find themselves in a situation where access is denied when editing hosts file on Windows. The pop-up message is very simple and does not provide any explanations:

Access is denied

OK

Before the emergence of the DNS, hosts files have been used for resolving hosts names. These files have a distinct syntax, which is easily recognizable on every operating system, including Windows, macOS, or Linux.[ref en-3] Therefore, the modification of the hosts file should be initiated in a very careful manner to prevent file damage. Due to this, the hosts file is often hidden, and access to it is restricted by the Windows OS itself.

In most of the cases, the “Access is denied” error aborts editing hosts file because the user does not have permission. The hosts file is located in the Windows installation directory, also known as root drive. The file is protected from unauthorized access, so if you’re not an authorized user of the target PC, you may encounter “Access is denied” error on Notepad. 

Luckily, you can fix Access denied when editing hosts file error relatively easily - simply follow the steps provided below.

Fix 1. Launch Notepad as administrator

If access is denied when editing hosts file, the first thing you should try is to access the file as an administrator:

  1. Open Windows search and type Notepad.
  2. Right-click on Notepad option and select Run as administrator.
  3. After the program launches, select File > Open.
  4. Navigate to the C:\\Windows\\System32\\drivers\\etc folder (make sure to change Text Documents (*.txt) to All Files).
  5. Select hosts file and click Open.
    Fix access denied when editing hosts file run as administrator
    Fix access denied when editing hosts file run as administrator
  6. Edit the hosts file and save it.

Fix 2. Run Notepad using Command Prompt

  1. Type in cmd into the search box.
  2. Right-click on Command Prompt result and select Run as administrator.
  3. Copy and paste the following commands into the window and press Enter after each:
    cd C:\\Windows\\System32\\drivers\\etc
    notepad hosts
  4. Make the changes to the hosts file, save them and close Command Prompt.
    Fix access denied when editing hosts file open hosts file via command prompt
    Fix access denied when editing hosts file open hosts file via command prompt

Fix 3. Transfer hosts file to another location

To fix "Access denied" alert while editing hosts file, try to move hosts file to a different location. Then edit it and move back to the initial location:

  1. Navigate to the C:\\Windows\\System32\\drivers\\etc and find your hosts file.
  2. Copy it to a different location, for example Desktop or any folder out of the Windows install directory.
    Fix access denied when editing hosts file copy to another location
    Fix access denied when editing hosts file copy to another location
  3. Then open the hosts file with Notepad and modify it.
  4. Save the changes. Then cut the file and paste it back to the C:\\Windows\\System32\\drivers\\etc directory.

Fix 4. Unmark Read-only option

Hosts file is set to Read-only by default. It means that the file cannot be edited in a regular way. To get permission to modify it, you should:

  1. Navigate to the C:\\Windows\\System32\\drivers\\etc directory.
  2. Find your hosts file, right-click it, and select Properties.
  3. Open Attributes section and uncheck the Read-only option.
  4. Click Apply and OK to save changes.

Fix 5. Modify security settings of the hosts file 

  1. Navigate to the C:\\Windows\\System32\\drivers\\etc directory.
  2. Find your hosts file, right-click it, and select Properties.
  3. Open Security tab and click Edit.
  4. Check the list of users that have access to hosts file. If your user name is included in that list, click it and set Permissions to Full control.
  5. If your user name is not included in that list, click the Add button and enter your user name.
  6. Click Check Names and hit OK.
    Fix access denied when editing hosts file give full control
    Fix access denied when editing hosts file give full control
  7. Now your user name should be added to the list. Click it and mark the Full control open next to your name.
  8. Click Apply and OK to save the changes.

Note: if your system was infected with ransomware or other malware which modified your hosts file, there is a high chance that your system files were affected as well. Due to this, the OS might experience slowdowns, errors, or even crashes, consequently pushing a thought of many to reinstall Windows altogether. To avoid that, we highly advise using [d1] - it can fix virus damage easily and stabilize the system without having to reinstall it.

Bottom line

To fix the 'Access Denied' error when editing the Hosts file, users can try running Notepad as an administrator, ensuring the file is not in use, or adjusting file permissions. If these solutions do not work, consider checking for malware or restoring the system to a previous state.

Frequently asked questions

The 'Access Denied' error occurs because the Hosts file requires administrative privileges to be edited. You need to run Notepad as an administrator to make changes.

To run Notepad as an administrator in Windows 11, right-click on the Notepad icon, select 'Run as administrator', and then open the Hosts file from the File menu.

If you still face issues, ensure that your user account has sufficient permissions and check if any security software is blocking access to the Hosts file.

Did this fix work for you?
Ryan Mitchell

Written & verified by

Hardware & Driver Specialist
Hardware troubleshooting Driver installation and rollback Device Manager errors USB and peripheral issues Firmware updates

Ryan Mitchell specialises in hardware troubleshooting and driver management for Windows systems. His expertise covers device recognition failures, driver conflicts, firmware updates, and peripheral connectivity issues across all major manufacturers. Ryan's systematic approach to hardware diagnosis — starting with Device Manager, working through driver rollback and clean installs, and escalating to BIOS-level checks — has made his guides a reliable resource for both home users and field technicians. He covers GPUs, printers, audio devices, USB controllers, network adapters, and external storage.

0 Comments

Be the first to comment

Still worried? Run a free check.

Paste any URL or domain — we'll scan it against 4.2M known threats in 10 seconds.

View full scanner → Add to your website →