Unable to Add New Hosts to etc/hosts-file

Hello all,

I’m following the instructions as described in “Jump Start PHP Environment” by Bruno Skvorc.
I’ve installed Virtualbox, Vagrant and Git.

Now I need to add new hosts to the file “hosts” in the folder C:\Windows\System32\drivers\etc
I open the file as an administrator add the suggested host as described in the book… homestead.app

and then I try to save it.
However, I am unable to change the contents as shown in a message:

“Cannot access hosts file because it’s being used by another process”

Any ideas?

It sounds like Windows considers it still being “used” by the text editor.

If you have saved the file and closed the editor, maybe you need to remove the file from the editors “quick load” (whatever it’s called)

Could you save the file with a different name, then rename the original (so you still have it) and rename the new one as hosts?

Hello Gandalf,

I can’t rename the file.
It says that the file is in use “in System”

Hello Mittineague,

I’m not sure what you mean with quick load

I use Notepad++ and it has “recent files” eg. if I’m working on “somefile.html” for a while and then I want to work on “somefile.css” for a while I can close the “somefile.html” tab. Later if I don’t want to navigate back to the “somefile.html” file to work on it some more, I can open it from “recent files”
In other words, Notepad++ keeps the file in its memory.

But I’m now wondering if you might have a localhost server running in the background as a service that is tying up the hosts file.

These are the programs running at the background.
I am not that experienced, but can you see a program that could cause the problem?

BTW I already tried taking full control of the document, but the problem persists

That’s because you can’t modify anything under the System32 folder while it’s running. You have to copy&paste the hosts file to the Desktop and modify it there, save your work, and then replace the old hosts file with the new one and you have to click on Continue when it prompts you the message asking you some general stuff.

Hello spaceshiptrooper,
After doing that It gives a message showing that I am not authorized to do this.

Snap a screenshot so I can see what it’s saying. You might want to restart your machine and then try again.

The messages are in Dutch :frowning:

I tried it again after a restart, but the problem still exists. (same messages)

Are you on an admin account?

Just checked to be sure, but yes I am logged in as the administrator

I’m guessing clicking on “Try again” will prompt the same message. I think you can use Take Ownership for this. Not sure if it actually works as I rarely use it since my first installations are always successful.

Try again does indeed prompt the same message and I already took full ownership.
This is so frustrating…

You’re saying you’ve already done this?

On a side note, if this isn’t on a VM, you can simply pop in a bootable USB or a DVD that has a copy of some sort of Linux OS, and use the live demo. You can then modify the hosts file from the Linux OS and save it directly into System32. I haven’t tried this yet, but I assume it will work. I’ll try it now.

Sorry for the long wait. I confirmed that you can do it via a Linux OS. I just ran my Ubuntu 15.10 DVD and it works just fine.

I had to Google translate some Dutch.

But the only thing that looks suspicious to me is
“Runtimeprocess in front of client-server”

Do you know what that is? I don’t have anything like that on my Windows 10 that I saw.

I found the culprit.
I had to untick “Lock hosts file” in my ZoneAlarm Firewall Settings.

Thanks for helping guys!


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.