cant write to Windows hosts file

Posted on 2013-11-27
Medium Priority
Last Modified: 2013-11-29
Hello EE,

I am signed in as a local admin on a windows 7 computer.  I am not signed as THE local admin though.  I am trying to update the hosts file for accessing other websites from another domain.  This is working on other computers currently that I have adjusted for these websites.  if I log on as THE local admin I can make the change.  If I logon as one of the other local admin accounts that are part of the local administrators group it doesnt work.  I have even gone as far as putting one of the local admin accounts as owner of the hosts file and yet when logged on as that account still can not make change to hosts file.  what can i do to correct this problem?  Thanks for your help!
Question by:12string
LVL 41

Accepted Solution

Mahesh earned 2000 total points
ID: 39681644
Try below

open cmd with run as administrator

then change directory to C:\windows\system32\drivers\etc

then type "notepad hosts" and enter

Now make your modifications and save and close

LVL 44

Expert Comment

ID: 39681751
By default, everything in %windir% and deeper is owned by "TrustedInstaller"

Take Ownership of the %windir%\System32\etc\drivers\etc folder, then give the new owner (I suggest giving ownership to the Administrators group) Full Control on the Permissions tab.Permissions - Administrators - Full Control (click for larger)
THEN running notepad as administrator will be able to save changes there.

Author Comment

ID: 39681755
Thank you MaheshPM that is another option but how do I change that back so that one doesnt have to do that step?  if the account is in local administrators and local admins have that ability then why does this happen?
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

LVL 41

Assisted Solution

Mahesh earned 2000 total points
ID: 39681784
The User Access Control are still enabled on Windows 7 machine by default....which forces you to open cmd \ applications with run as administrator

You can disable these controls through Control Panel \ user accounts \ change user account settings  and just pull the slider to complete bottom (Never Notify)

OR you can disable all UAC through gpedit.msc under computer configuration\windows settings\security settings\local polices\security options, you need to disable those settings starting from user access control (specifically admin approval modes)

OR you can use domain level GPO to disable above these settings

OR you can just disable through registry also.

Its not recommended to modify NTFS security on System folders


Author Closing Comment

ID: 39682033
Thank you Mahesh I was wondering whether I would have to use gpedit but didnt want to waste the time looking the exact location.

Also Thanks Darr247 I did do that as well, before I came to EE, but still got same problem.  took ownership using a specific local acct and then logged on as that acct.
LVL 59

Expert Comment

ID: 39682413
Let me add something about the stuff behind this "effect".
First: UAC introduced these type of effects and UAC came with vista. How come that after 7 years, this problem is still not fully understood by anyone? :))

1. You are logged in as some admin, not as the account "administrator". With default settings, the UAC is off for the account "administrator" even when it's on for the rest. That's why it works with the admin called “administrator” and not with any others.

2. If, as in this case, the ACL of a file does hold the group "administrators" with at least change permissions and NOT everyone AND NOT authenticated users [and not your own account] - then you CANNOT modify the file EVEN when you are a member of the admins group. [By the way: the ownership does not matter]
Why is that so? Because of the UAC. The UAC introduced the concept of elevation [see 3.]. Without "elevating", members of the admin group are treated as weak, restricted users. From the perspective of the ACL, they don't even belong to the group administrators!

3.How to elevate? Now for the most important part...
The host file is usually opened with notepad. Microsoft, in their enormous generosity, has been providing this square and simple program for ages. Problem: it is NOT UAC-aware! It won't TRIGGER elevation. The process of elevating (after "dimming the screen") would need you to click ok on a dialogue that asks for consent, that's all. But notepad is too simple to provide that :) It has not been made compatible with MS’ own technology. Too bad. By the way: task manager is another program that misses to trigger elevation under some circumstances. Poor work.
What can we do? We can…
-modify the ACL of the file to simply hold hold our own account name! or…
-elevate the viewer (notepad) manually by right clicking notepad.exe and selecting “run as administrator”. Or…
-use runas on notepad providing the credentials of the “real” administrator. Or…
-save the file somewhere else and later, push it over to its final destination using explorer! Explorer is UAC aware and will trigger elevation while we move that file and overwrite the old one.
Turning off UAC is not the way to go, believe me.

4. There is even more to it: there is a little known security feature called “mandatory integrity controls/levels” (“MIC”/”MIL”) that can also cross your plans! Think of it as some kind of extra security layer next to the NTFS ACL. If some files/folders are set to have an MIL of “high”, then only elevated processes may write to it. Writing to the root of c:\ is such an example, too.
ILs can be read out and modified by tools like chml.exe

Spread the word

Author Comment

ID: 39685552
Thanks McKnife for the explanation.  To answer your question:

<How come that after 7 years, this problem is still not fully understood by anyone?>

My customers were more win xp than win vista, there was very little need to know or work with win vista ergo the need to ask why this problem exists.

Thanks for the insight and yes I will pass the info on, I know quite a few people will be interested in this answer

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Nuance's PaperPort may display this error message: PaperPort appears to be running Windows XP Compatibility Mode which may result in errors. We recommend disabling Compatibility Mode for the PaprPort.exe program, see Technote 6629. This articl…
One thing I've always found frustrating is no matter how many times one asks the end users to not save things on their local machines, they do it anyway.  Forget that we don't back up the desktops - only the servers.  Well, let's sneak their data on…
This Micro Tutorial will give you a basic overview of Windows Live Photo Gallery and show you various editing filters and touches to photos you can apply. This will be demonstrated using Windows Live Photo Gallery on Windows 7 operating system.
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

568 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question