failure to edit hosts file permissions

1.1k views Asked by At

I am attempting to write a batch file for editing the hosts file. I recieve access is denied when I attempt this:

cacls hosts /e /p %username%:w

what should my command look like? I can do it graphically by hand so I know its doable

Thanks in advance

2

There are 2 answers

0
hazymat On BEST ANSWER

It's possible you may need to also do the following:

  • take ownership before attempting to change ACL permissions. Use takeown /F blah.txt
  • Windows hosts file starts off life as read-only. To unset it as read-only (in order to write to it), use attrib -R blah.txt

Don't forget you may need to run takeown in context of local administrator for it to work...

0
Simon Catlin On

Although the above has been accepted as the answer, there's a very good chance that UAC is kicking in.