1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| public static void AddDirectorySecurity(string pFolder, string pAccount, FileSystemRights pRights, AccessControlType pControlType, bool pDeleteExist)
{
// Create a new DirectoryInfo object.
DirectoryInfo dInfo = new DirectoryInfo(pFolder);
// Get a DirectorySecurity object that represents the
// current security settings.
DirectorySecurity dSecurity;
if (pDeleteExist)
dSecurity = dInfo.GetAccessControl();
else
dSecurity = new DirectorySecurity(pFolder, AccessControlSections.All);
dSecurity.AddAccessRule(new FileSystemAccessRule(pAccount
, pRights
, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit
, PropagationFlags.None
, pControlType));
// Set the new access settings.
dInfo.SetAccessControl(dSecurity);
} |
Partager