When trying to update and save your Windows hosts files you may receive the error message “Unable to set new owner on hosts. Access is denied.”.
Adding in static host entries to the hosts file is something that you may do semi-regularly, if you are a developer or perhaps in some IT lab situations, so this is an annoying situation to be presented with.
The following is just one possible solution that I found when coming across this problem.
I knew from past experience that this is most likely a permissionings issue, though after confirming that my user account did have permissions to save/modify the hosts file and then when trying to assign my Windows user account “Owner” privileges, as a last resort, I received the “Access is denied” message.
I had also confirmed that my user account had local administrative rights on the PC and also that nothing had the hosts file open.
How to Resolve
After a reboot, with the same result and a little head scratching, I decided to have a look at my installed antivirus (Avira) software – just in case. Sure enough, upon disabling the real-time anti-virus detection I could then successfully save my updates hosts file!
Upon reflection this makes total sense as an easy exploit would be to insert rogue entries into a PC’s hosts file and then have the user hit compromised identical looking web sites that could then go on to do all manner of undesirable things that could see your personal and financial details fall into the wrong hands.
I wouldn’t recommend adding an exception for the hosts file in your AV software, as this counteracts the protection the AV is trying to provide. Instead just temporarily disable any real time AV protection whilst your save any changes to your hosts file.
So the moral behind the story is: after confirming that your user account should be able to save any changes to the hosts file and that nothing has the file open already then definitely take a look at your antivirus software to see if that is protecting the file.