How to deny delete/modify permission to a file?

10,921

On Windows, it is enough to have one of:

  • "Delete" on the object, or
  • "Delete child" on its parent

Therefore a file will only become undeletable if you deny both.

Use icacls to edit the permissions:

  • Deny "Delete" to the file:

    icacls Reflector.exe /deny Everyone:(D)
    
  • Deny "Delete child" to the folder:

    icacls . /deny Everyone:(DC)
    

(Tested on Windows XP.)

Share:
10,921

Related videos on Youtube

Ian Boyd
Author by

Ian Boyd

Updated on September 18, 2022

Comments

  • Ian Boyd
    Ian Boyd over 1 year

    I want to deny myself the ability to modify or delete an executable.

    When .NET Reflector asks you if you want to update:

    enter image description here

    and you choose No it spontaneously deletes itself as retribution:

    enter image description here

    So I want to prevent myself from being able to Delete the executable; as punishment for their punishment.

    I tried to Deny me Write permission (and deny it to Everyone, and Administrators):

    enter image description here

    Except, I can still Right-Click -> Delete the file...

    How do I deny the delete/modify permission to a file?

    • surfasb
      surfasb almost 13 years
      Yeah, write access has nothing to do with delete permission. This seems like a rather draconian way to solving this problem.
    • Ian Boyd
      Ian Boyd over 12 years
      @surfasb Write access very well may have nothing to do with delete. i only include things i've tried because some people get grump when i simply ask the question. And some people will give spiteful downvotes if i don't "show research effort".
    • Mark K Cowan
      Mark K Cowan over 9 years
      Upvote solely because I find the question quite amusing. Then I recalled painful times with the Adobe Flash installer and suddenly I feel less amused.
  • Ian Boyd
    Ian Boyd almost 13 years
    Denying Modify permission also removes Execute permission; and i can still delete the file!
  • user1686
    user1686 almost 13 years
    As I said, "You may also have to deny "Delete items" on the folder"... Which too can be done with icacls.
  • Ian Boyd
    Ian Boyd almost 13 years
    On the downside that would deny the ability to delete other items in the folder. Given that it doesn't seem to be working, i presume it is not possible to deny the ability to delete a file - deletes must happen against folders, rather than files.
  • Ian Boyd
    Ian Boyd almost 13 years
    Edit your answer to indicate that it cannot be done, "But here are some alternatives that might be useful", and you'll get the accept.