Hosts file is locked

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Hosts file is locked

Post by hawleyjr »

On my Winxp dev machine running xampp lately I have been unable to modify the hosts file

C:\WINDOWS\system32\drivers\etc\hosts

As you know this file contains the mappings of IP addresses to host names and is needed for virtual hosts.

The error I'm getting is the file is read only or is opened by another application.

Any ideas how to unlock this file? Or figure out what application is using it.

yes, I've right clicked and made sure it's not 'read only' :roll:
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

Hmm Sometimes I've had programs hang on to files even though I think the programs was closed. Lately I've had trouble with Programmers Notepad. Try looking at your applications manager or reboot.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

I can guarantee that XAMPP isn't the one doing that. It doesn't access that file at all.

It sounds like you have some network program that is locking the file. Have you added anything new from just before the problem happened to now, other than XAMPP?

As to finding out what application has hold of it I wish I knew. If someone knows how to track what programs have locks on what files I would love to know it as well. I have had windows screw things up like that as well.

When that has happened to me it has at least been on a file I wanted to delete. What I have had to do in the past is...

1. Reboot and tap F8 while rebooting until the boot screen appears.

2. Select boot with Safe Mode Command Prompt.

3. CD to the directory where the file is located.

4. Delete the file and reboot.

5. Then use a registry cleaner like Norton's WinDoctor to remove any registry entries that might have been associated with the deleted file.

A pain in the ass but about the only way I have found to fix the problem when it occurs. You can do basically the same thing but make a backup copy of the hosts file before you do this. Then copy it back when you are finished.
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

WOW, I shouldn't say it but I can't resist.

Windows sucks.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

I've encountered this problem before. I believe it's a bug in Windows. The only way I was able to to delete a file once was to..

1. Open the task manager
2. End Task on Explorer (not Internet Explorer)
3. Using the task manager, open a terminal
4. Delete the file
5. Using the task manager, restart Explorer

Spose that won't work for editing it though..
Post Reply