user457028
user457028

Reputation:

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

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 file through group membership...

Upvotes: 1

Views: 1422

Answers (2)

Patrick
Patrick

Reputation: 23619

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.

Upvotes: 0

Zooba
Zooba

Reputation: 11438

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.

Upvotes: 1

Related Questions