31

I'm trying to edit my hosts file in Windows 8 Pro.

When I open C:\Windows\System32\Drivers\etc\hosts in Notepad++ or any other text editor, make changes and attempt to save, I get a dialog that tells me "Save failed: Please check if this file is opened in another program."

I can't think of what would be using it (other than a browser, IIS, and Windows Defender). I've never encountered this problem in Windows 7. I have used Process Explorer to try and identify any processes that are currently using the hosts file, but when I search Process Explorer for the "Handle or DLL substring" 'hosts' it doesn't return anything. I've looked around Process Explorer to see if there is any other way to search for processes consuming the file, but haven't had any luck.

I've also tried simply stopping the Windows Defender service and stopping the WWW Service.

5
  • 1
    Process Explorer itself has been known to sometimes keep a file open. Also make sure you run notepad As Administrator. I've had no issues editing hosts file in win8. Sep 18, 2012 at 16:17
  • 2
    Running as Administrator was the answer, Thanks Bret.
    – David Sulpy
    Sep 18, 2012 at 16:27
  • Don't overlook excluding hosts file from Windows Defender, amongst any other AV programs installed, before attempting to modify it following the advice here. See here for further instructions; howtogeek.com/122404/…
    – user341610
    Jul 6, 2014 at 8:09
  • Related: hosts file ignored, how to troubleshoot? on Server Fault.
    – Arjan
    Jun 21, 2015 at 13:46
  • -1 You write that you get this error in any text editor "Save failed: Please check if this file is opened in another program" <-- I do not believe you. I google that and from the results i've seen, only notepad++ comes up
    – barlop
    Jul 24, 2015 at 8:43

6 Answers 6

33

You have to run Notepad++ as administrator. Otherwise you won't have the neccessary permissions to edit that file.

6
  • 1
    Is there any way to make it so you don't have to run as admin to edit that file?
    – Sawtaytoes
    Sep 18, 2012 at 17:48
  • Not that i'm aware of.
    – Frederik
    Sep 18, 2012 at 18:31
  • 1
    @Saturn2888 I would highly advise that you not change the permissions. Otherwise, A virus could hijack all of your webbrowsing by injecting DNS entries into it for the websites you go to, and redirect you to malicious websites. Sep 18, 2012 at 18:51
  • If you're frustrated with the whole Run as Admin thing here's how you can use the Shell Extension shortcut to do this: 1) Right click hosts file -> Open in Notepad++ 2) Close Notepad++ 3) Run Notepad++ as administrator. The file should be still open as N++ remembers the last file(s) you had open. Saves you digging through the file-open dialog.
    – Aren B
    Sep 18, 2012 at 19:48
  • @Aren B Sadly, Notepad++ run as admin completely forgets all tabs I had open as a user. It's really annoying.
    – Sawtaytoes
    Sep 22, 2012 at 1:52
10

If you actually have administrator rights, then you're probably fighting against UAC. Make sure to launch your favorite text editor by right-clicking on it and selecting "Run as administrator".

1
  • Great point. I am running as a user with administrative rights. Sep 18, 2012 at 16:40
3

I had the same case, and couldn't change the hosts file even after I checked if I had all the permissions in the user settings or the hosts file's permissions.

ANSWER: Some antivirus software (in my case AVIRA)blocks everything in changing hosts files in their security options. Disable it for a minute, and change. Be careful, it can be risky!

1
  • AVIRA was the problem in my case thx for the hint!
    – IvanL
    Feb 7, 2014 at 16:10
2

You may also want to check your permissions on the host file itself. You may run as administrator but you may not have the rights to edit the file.

2

Copy the hosts file to another location on the PC (like Documents) and edit in that location. copy hosts file back to original location. Worked for me.

1
  • this achieves the same result as @BenFisher 's comment... IF a permission dialog pops up during the file replace and IF the file is not in use. Sep 19, 2013 at 22:54
0

Running as admin didn't work in Windows 8 for me. Here's what I did to solve the problem:

  • Disconnect from net by unplugging network cable (or disable wireless)
  • Find hosts file. right click --> properties --> security
  • Click Users then edit
  • Add write for users (admin has write but didn't work)
  • Edit file by running notepad as admin
  • Save file
  • Remove write for users
  • Reconnect to net.
2
  • it would be nice if the person who marked this as un helpful left a little note saying why it was unhelpful. this worked for me when the above advice was not working. thanks to peter for the tip.
    – nero
    Jun 27, 2013 at 9:46
  • Probably because it appeared to be more of a comment than an answer. I've edited your answer to be a little more readable, and recognizable as an answer. Jun 27, 2013 at 14:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .