Monday, April 24, 2006

How can I programmatically “grant permissions to a specific user to access a specific windows folder share”. using C#?
Using this library and the following code you can grant permissions to user for a folder share programmatically.
SecurityDescriptor desc = SecurityDescriptor.GetNamedSecurityInfo (

shareHandle,
SE_OBJECT_TYPE.SE_LMSHARE,
SECURITY_INFORMATION.DACL_SECURITY_INFORMATION);
Dacl dacl = null;

if (desc == null)
{
desc = new SecurityDescriptor();
desc.AllocateAndInitializeSecurityDescriptor();
dacl = new Dacl();
}
else
{
dacl = desc.Dacl;
}

dacl.AddAce (new AceAccessAllowed (new Sid ("BUILTIN\\Administrators"), AccessType.GENERIC_ALL));
dacl.AddAce (new AceAccessAllowed (new Sid ("Everyone"),

AccessType.GENERIC_READ
AccessType.GENERIC_EXECUTE
AccessType.READ_CONTROL
AccessType.STANDARD_RIGHTS_READ));
desc.SetDacl(dacl);
desc.SetNamedSecurityInfo(faxShare,
SE_OBJECT_TYPE.SE_LMSHARE ,
SECURITY_INFORMATION.DACL_SECURITY_INFORMATION);

No comments: