Teun.ToString()

by Teun Duynstee [Macaw]

<December 2008>
SuMoTuWeThFrSa
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910


Navigation

Subscriptions

News

I discontinued this blog. I now post at: www.TeunToString.net



Download Finch PocketBlogger

Post Categories

Article Categories



System.Security.AccessControl; nice, but how to check for access rights?

The november 2004 issue of MSDN Magazine has a nice overview article on using the .NET 2.0 classes in the System.Security.AccessControl namespace. These classes allow you to access and modify the security descriptors on files, directories and other system objects. The article shows how to grant or deny rights on files to users from code, enumerate all ACE's in the ACL, take ownership, all from managed code.

Still, there seems to be no way to check for a specific right (say: write) for a specific SID (say: the current user). It seems to me that any application that allows a user to edit or display security settings should also be able to grey out the 'security' menu item when the current user lacks the privileges to view the security settings.

Am I missing something? Is there some HasAccess() method that I haven't found on msdn2? Am I really supposed to try/catch to know if the current user may edit a file?

Update: a colleague (thanks Emile) pointed me to this article on wrapping the AccessCheck API call from advapi32.dll. Code is in VB.NET and comes with samples. Uses .NET 1.1, so no integration with the new classes in System.Security.AccessControl

posted on Tuesday, December 07, 2004 6:54 PM by TeunD


# re: System.Security.AccessControl; nice, but how to check for access rights? @ Friday, August 24, 2007 3:12 AM

I am facing the same problem. Actuvally i want to remove some user permission from the folder or want to delete that user permantaly from the folder permission.
I had witten the code for the same but that code removes only explicit permission from the folder and not inherit permission.

my code looks like this:

public static void RemoveDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType)
{
// Create a new DirectoryInfo object.
DirectoryInfo dInfo = new DirectoryInfo(FileName);

// Get a DirectorySecurity object that represents the
// current security settings.
DirectorySecurity dSecurity = dInfo.GetAccessControl();

// Add the FileSystemAccessRule to the security settings.
dSecurity.RemoveAccessRule(new FileSystemAccessRule(Account,
Rights,
ControlType));

// Set the new access settings.
dInfo.SetAccessControl(dSecurity);

}


i want a way to remove inherit permission from particular folder

sachin




Powered by Dot Net Junkies, by Telligent Systems