5

As a full-time Web Developer I am constantly adding fake domains to my Windows 7 HOSTS file to point a domain to my localhost web server that I develop on.

I have even built a nice little PHP script that lets me enter in the domain name I want to create, for example testing.dev

My script then creates...

  • appropriate folders for this new website in my server directory
  • VirtualHosts record in Apache (actually uses a Wildcard setup /projects/testing.dev/www/)
  • Creates a MySQL database testing.dev and associates a MySQL User to this new DB
  • Lastly I have a small .EXE file that gets passed in a variable "testing" and it then edits my Windows HOSTS file and addes an entry on a new line like this... 127.0.0.1 testing.dev which then allows me to acces my new project site in the browser at http://testing.dev

This setup has worked amazingly for the past 2 years but recently my .EXE program has quit working...upon inspection if I browse to the folder C:\Windows\System32\drivers\etc and view the properties for the hosts file in this folder, the first problem I see is the read-only checkbox is checked, which is not allowing my simple exe program to modify the hosts file and add my new entries.

I then have to un-check read-only and manually add in my new hosts file changes and save, which then works fine. THe whole point of having a custom .exe program that takes 1 parameter (the domain name) is to be able to built scripts like this to automate the editing of my hosts file and work it into workflows like I have done.

Everytime I change this setting by un-checking the read-only property and apply/save it, within minutes it seems to have reverted back to being checked!

I would really appreciate any help in making my un-checked status to stick and stay that way, any ideas, suggestions, or even better a real solution to my problem anyone?

Also just to mention I do not have any kind of firewall or security programs that would be doing this, no 3rd part stuff running which would cause this.

Thanks for any help

enter image description here

1

4 Answers 4

0

Perhaps this problem is because some other program is doing this. I would recommend clearing out all of your temp files and see if this stops your problem. Hope this helped otherwise it might be something in your registry.

0

Try changing the attributes using CMD. Start Computer in safe mode with Command Prompt.

Type

cd C:\Windows\System32\drivers\etc (Hit Enter)

attrib C:\Windows\System32\drivers\etc\hosts -r (hit enter)

further check if your file shows read only checked or not

0

I can't test that this for sure works because for me the file isn't marked read-only as in your case, but this is a method I've used to prevent Windows from reverting my changes to slui.exe protected files.

You'll want to modify the permissions of the file and deny access to SYSTEM and possibly TrustedInstaller (but not yourself). You may need to make yourself the owner of the file to be able to do this.

Go to properties > security > advanced > change permissions
Then edit the permissions for SYSTEM and check deny for writing attributes/extended attributes. If that doesn't work, you can try denying it full control at your own risk.

If you need to take ownership of the file to do any of this, it's in properties > security > owner > edit

Finally, as a last resort, you can make the program unmark read-only whenever it modifies the file. I don't know PHP, so I can't help with this. You could try the command suggested in Stephen's answer.

0

Maybe it's not a strict anwser , but i'm think that you trying to reinwent the well :)

Install laragon (https://laragon.org/) as your wamp server (instead apache/php or what you have there)

Laragon have it solved (for any folder that you create in project there is automaticlly created fakedomain for it )

I'm also a php developer , and trust me all problems with apache/php extension/php versions and .local domains have ended with laragon

You must log in to answer this question.

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