Search code examples
batch-filecmdhostscacls

failure to edit hosts file permissions


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


Solution

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