开发者

Checking if a user has read permissions for a file in windows

开发者 https://www.devze.com 2023-01-19 02:19 出处:网络
How do you check to se if a user has read permissions for a file in windows? There is the possibility to read the authorization rules via File.GetAccessControl. This does not tell me if the user has t

How do you check to se if a user has read permissions for a file in windows? There is the possibility to read the authorization rules via File.GetAccessControl. This does not tell me if the user has the right to read the fil开发者_如何转开发e through group membership...


Read the file. If you can read it, you have permission.


This is actually the intended model here. Even if you check the permissions before trying to read, there is the possibility that they will change before you get to your read. You are supposed to attempt to read the file (CreateFile will fail if you cannot) and beg forgiveness (handle the error) afterwards.


The C "access" runtime function can be used to check the access. I'm not sure whether it checks all Windows levels (group, user, ...). Just try it out.

0

精彩评论

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