1

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

jth41
  • 3,808
  • 9
  • 59
  • 109

2 Answers2

1

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...

hazymat
  • 404
  • 1
  • 6
  • 20
1

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

Simon Catlin
  • 2,141
  • 1
  • 13
  • 15