开发者

Which permissions are needed to delete a file in windows

开发者 https://www.devze.com 2023-03-06 05:05 出处:网络
In CreateFile() has DesiredAccess Like GENERIC_READ, GENERIC_WRITE, F开发者_开发问答ILE_READ_ATTRIBUTES, etc.

In CreateFile() has DesiredAccess Like GENERIC_READ, GENERIC_WRITE, F开发者_开发问答ILE_READ_ATTRIBUTES, etc.

My question is what is the minimum/exact permissions needed to solely delete a file in the system?

Thanks


If you just want to delete a file, use the DeleteFile function.

It's documentation details what permissions you need, and a few things you should know, like:

If you request delete permission at the time you create a file, you can delete or rename the file with that handle, but not with any other handle.

There is good information in that documentation page, including a link to File Security and Access Rights.

Look at the ACCESS_MASK page linked from the OpenFile documentation page for the actual delete access right flag - it's simply called DELETE.

But a word of warning: this type of check is always racy. The file permissions can change between your access right check and a subsequent delete. (Time of check/time of use.)


You only need DELETE access, I believe. It's not a file access right, it's a standard access right.

It's not easily found that these standard access rights are allowed, but the MSDN page on file access rights states:

The valid access rights for files and directories include the DELETE, READ_CONTROL, WRITE_DAC, WRITE_OWNER, and SYNCHRONIZE standard access rights.

0

精彩评论

暂无评论...
验证码 换一张
取 消