Re: Check permissions on Folder
- From: "Fred W." <fredwemail-news@xxxxxxxxx>
- Date: Tue, 19 Sep 2006 11:57:58 -0400
If I'm understanding this correctly then I will need to walk through the
"FileSystemAccessRules" and accumulate what's allowed and denied. I will
also need to interpret if the user is a member of that group for each rule.
My understanding is that explicit rules take precedence over inherited rules
(can I tell the difference?). Also, denied take precedence over allowed. Do
I just assume owners have full control?
This just seems like a lot of work for something windows does for you when
you try to create, delete, modify files and folders. I can't help but think
there must be a better solution. I basically want the Effective Permissions
tab in Windows Explorer Properties. I've run across references to an
"AccessCheck" function (for Win32), but I have yet find anything
specifically for .NET. I suppose I could wrap the Win32 dlls, but I'm still
holding out for a .NET solution. Another solution I've been considering is
just creating a temporary files and folder in the folders I want to check
and catch exceptions to determine what's allow when I try to manipulate. Of
course I could end up littering files if I can't delete them.
Any additional comments are appreciated. Thank you.
-Fred
"Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx> wrote in message
news:eKAaQa32GHA.4932@xxxxxxxxxxxxxxxxxxxxxxx
"Fred W." <fredwemail-news@xxxxxxxxx> wrote in message
news:%23UtzDx22GHA.3344@xxxxxxxxxxxxxxxxxxxxxxx
|I suppose I don't need full control, but just "Read, Write, and Append"
| capability (Or perhaps you have another suggestion?).
|
| Which classes specifically? Do I need to call
"Directory.GetAccessControl"
| and then iterate through the "AccessRules" or is there a function I can
call
| to check for "Read, Write and Append" access on a directory. Thanks
|
| Fred
|
|
|
Following sample enumerates the ACE collection of a Directory object and
prints the FileSystemRights for the administrators group.
NTAccount acc = new NTAccount("administrators");
SecurityIdentifier secId = acc.Translate(typeof(SecurityIdentifier))
as SecurityIdentifier;
DirectoryInfo dInfo = new DirectoryInfo("c:\\");
DirectorySecurity dSecurity = dInfo.GetAccessControl();
AuthorizationRuleCollection rules = dSecurity.GetAccessRules(
true,
true,
typeof(SecurityIdentifier) );
foreach(FileSystemAccessRule ar in rules)
{
if(secId.CompareTo(ar.IdentityReference as SecurityIdentifier) ==
0)
Console.WriteLine(ar.FileSystemRights);
}
Hope it helps.
Willy.
.
- Follow-Ups:
- Re: Check permissions on Folder
- From: Willy Denoyette [MVP]
- Re: Check permissions on Folder
- References:
- Check permissions on Folder
- From: Fred W.
- Re: Check permissions on Folder
- From: Willy Denoyette [MVP]
- Re: Check permissions on Folder
- From: Fred W.
- Re: Check permissions on Folder
- From: Willy Denoyette [MVP]
- Check permissions on Folder
- Prev by Date: Re: System.Windows.Forms namespace
- Next by Date: Re: find out if an instance of type type (indirectly) derives from
- Previous by thread: Re: Check permissions on Folder
- Next by thread: Re: Check permissions on Folder
- Index(es):
Relevant Pages
|