Editing hosts file on Windows 8

31

9

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.

David Sulpy

Posted 2012-09-18T16:09:07.300

Reputation: 2 179

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; http://www.howtogeek.com/122404/how-to-block-websites-in-windows-8s-hosts-file/

– None – 2014-07-06T08:09:19.223

Related: hosts file ignored, how to troubleshoot? on Server Fault.

– Arjan – 2015-06-21T13:46:44.160

-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 – 2015-07-24T08:43:10.420

1Process 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. – Bret Fisher – 2012-09-18T16:17:44.117

2Running as Administrator was the answer, Thanks Bret. – None – 2012-09-18T16:27:02.263

Answers

33

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

Frederik Nielsen

Posted 2012-09-18T16:09:07.300

Reputation: 458

There is a Notepad++ plugin called "Save as admin" which will ask for admin permission (UAC prompt) when you save the hosts file. – Robert – 2015-07-30T09:44:17.507

1Is there any way to make it so you don't have to run as admin to edit that file? – Sawtaytoes – 2012-09-18T17:48:52.080

Not that i'm aware of. – Frederik Nielsen – 2012-09-18T18:31:12.187

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. – Darth Android – 2012-09-18T18:51:42.373

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 – 2012-09-18T19:48:16.110

@Aren B Sadly, Notepad++ run as admin completely forgets all tabs I had open as a user. It's really annoying. – Sawtaytoes – 2012-09-22T01:52:16.790

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".

Massimo

Posted 2012-09-18T16:09:07.300

Reputation: 2 278

Great point. I am running as a user with administrative rights. – David Sulpy – 2012-09-18T16:40:02.617

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!

Frankl

Posted 2012-09-18T16:09:07.300

Reputation: 31

AVIRA was the problem in my case thx for the hint! – IvanL – 2014-02-07T16:10:29.130

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.

Peter

Posted 2012-09-18T16:09:07.300

Reputation: 21

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.

user255834

Posted 2012-09-18T16:09:07.300

Reputation: 21

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. – Lorenzo Von Matterhorn – 2013-09-19T22:54:22.583

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.

nero

Posted 2012-09-18T16:09:07.300

Reputation: 11

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 – 2013-06-27T09:46:49.697

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. – James Mertz – 2013-06-27T14:18:17.000