My executable can't call Directory.GetAccessControl on a directory it
doesn't have rights to (System Volume Information). That blows my
mind! Is there a way to find out whether I have rights without
handling an exception?
Thanks,
Travis
P.S. - This is just me playing around and being curious.
<jehuga...@gmail.com> wrote in message
news:35819941-0daf-4e90...@m3g2000yqf.googlegroups.com...
> My executable can't call Directory.GetAccessControl on a directory it
> doesn't have rights to (System Volume Information). That blows my
> mind! Is there a way to find out whether I have rights without
> handling an exception?
Exceptions are just information. Use that information to your advantage
instead of trying to avoid it.
Well, to be fair: the cost of an exception could be significant if the
code is trying to examine a large number of directories in a short
period of time. If there were an alternative, it might be worth looking
into.
However, as Phil points out, not being able to get information about a
directory the code doesn't have access rights for is a security feature,
and a potentially important one at that.
Pete
Well, here is a dumb question: When I say Directory.GetDirectories, it
will return System Volume Information. If I can see that it is in my
directory, why shouldn't I be able to get access information for it?
It just depends on the access settings. If someone has set the access
settings to prohibit the retrieval of access settings for a specific
process, that process can't get the access settings.
Sometimes the information of who _is_ allowed to access a given file is
in and of itself sensitive information. Even the information of who
else is not allowed could be, in fact.
If you feel that there's no good reason for users without actual access
to the file to be restricted from looking at the access settings, you
could ask the admin to change the settings for that file, to allow
unrestricted access to the access settings.
Pete
Hmm. Like I said, it is purely academic. I was playing around with F#
today, trying to make a simple recursive file navigator. I was hoping
for an elegant way of navigating directories, without using the built
in GetFiles methods, obviously. Thanks all!
Exceptions are great, but should only be used for exceptional
situations not for an expected situation.
Not so much for performance but for clarity in code.
Whether the specific case is an exceptional or expected
situation I will leave to the original poster.
Arne