diff --git a/NTFSSecurity/Extensions.cs b/NTFSSecurity/Extensions.cs index 5ae4956..82d5e43 100644 --- a/NTFSSecurity/Extensions.cs +++ b/NTFSSecurity/Extensions.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.Linq; +using System.Security.AccessControl; using Alphaleonis.Win32.Filesystem; namespace NTFSSecurity @@ -52,5 +54,10 @@ namespace NTFSSecurity throw new System.IO.FileNotFoundException(); } } - } + + public static List GetListOfNames(this Enum source) + { + return Enum.GetValues(typeof(T)).Cast().ToList(); + } + } } \ No newline at end of file diff --git a/NTFSSecurity/NTFSSecurity.csproj b/NTFSSecurity/NTFSSecurity.csproj index d5d189e..eac4d7d 100644 --- a/NTFSSecurity/NTFSSecurity.csproj +++ b/NTFSSecurity/NTFSSecurity.csproj @@ -23,7 +23,7 @@ true full false - ..\..\..\..\..\..\Program Files\WindowsPowerShell\Modules\NTFSSecurity\ + ..\..\..\..\Documents\WindowsPowerShell\Modules\NTFSSecurity\ TRACE;DEBUG prompt 4 diff --git a/Security2/FileSystem/FileSystemSecurity2.cs b/Security2/FileSystem/FileSystemSecurity2.cs index cd5eb08..43c0be3 100644 --- a/Security2/FileSystem/FileSystemSecurity2.cs +++ b/Security2/FileSystem/FileSystemSecurity2.cs @@ -1,5 +1,6 @@ using Alphaleonis.Win32.Filesystem; using System; +using System.Linq; using System.Security.AccessControl; namespace Security2 @@ -99,14 +100,26 @@ namespace Security2 public void Write() { - if (isFile) + var values = Enum.GetValues(typeof(System.Security.AccessControl.AccessControlSections)); + foreach (var value in values) //.Cast().Where(v => v != "All" | v != "None")) { - ((FileInfo)item).SetAccessControl((FileSecurity)sd); - } - else - { - ((DirectoryInfo)item).SetAccessControl((DirectorySecurity)sd); + try + { + if (isFile) + { + ((FileInfo)item).SetAccessControl((FileSecurity)sd, (AccessControlSections)value); + } + else + { + ((DirectoryInfo)item).SetAccessControl((DirectorySecurity)sd, (AccessControlSections)value); + } + } + catch + { + //Console.WriteLine("Exception {0} - {1}", item.FullName, value); + } } + } public void Write(FileSystemInfo item) diff --git a/TestClient/Program.cs b/TestClient/Program.cs index a7b3bc6..f388197 100644 --- a/TestClient/Program.cs +++ b/TestClient/Program.cs @@ -15,6 +15,17 @@ namespace TestClient { static void Main(string[] args) { + //List fileSystemRights = new List(); + + //var values = Enum.GetValues(typeof(AccessControlSections)).Cast ().ToList(); + + //var v1 = values.Where(v => v == AccessControlSections.All).FirstOrDefault + + var x = Enum.get + + + + var item1 = new FileInfo("D:\\file1.txt"); var item2 = new DirectoryInfo("D:\\test3"); var account1 = new List() { (IdentityReference2)@"raandree1\randr_000" };