/// <summary> /// Initializes a new instance of the <see cref="FileSystem" /> class. /// </summary> /// <param name="root">The absolute path to the root directory of this file system (..../Pie/ or .../Pie).</param> public FileSystem(String root) { // Append separator to root, if it hasn't got it _fileSystemRoot = root + (root.EndsWith(PathSeparator) ? String.Empty : PathSeparator); DirectoryInfo dirInfo = new DirectoryInfo(_fileSystemRoot); // Create directory if it doesn't exist if (!Directory.Exists(_fileSystemRoot)) { Directory.CreateDirectory(_fileSystemRoot); } // Make sure the directory has the right permissions try { // Attempt to get a list of security permissions from the folder. // This will raise an exception if the path is read only or do not have access to view the permissions. System.Security.AccessControl.DirectorySecurity ds = Directory.GetAccessControl(_fileSystemRoot); } catch (UnauthorizedAccessException) { var security = new DirectorySecurity(); var windowsIdentity = WindowsIdentity.GetCurrent(); if (windowsIdentity != null) { var id = windowsIdentity.User; var rule = new FileSystemAccessRule(id, FileSystemRights.FullControl, AccessControlType.Allow); security.AddAccessRule(rule); dirInfo.SetAccessControl(security); } } }
public static void TakeOwnership(string FD) { try { var myProcToken = new AccessTokenProcess(Process.GetCurrentProcess().Id, TokenAccessType.TOKEN_ALL_ACCESS | TokenAccessType.TOKEN_ADJUST_PRIVILEGES); myProcToken.EnablePrivilege(new Microsoft.Win32.Security.TokenPrivilege(Microsoft.Win32.Security.TokenPrivilege.SE_TAKE_OWNERSHIP_NAME, true)); SecurityIdentifier identifier = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null); NTAccount identity = (NTAccount)identifier.Translate(typeof(NTAccount)); if (File.Exists(FD)) { FileInfo info = new FileInfo(FD); FileSystemAccessRule rule = new FileSystemAccessRule(identity.Value, FileSystemRights.FullControl, AccessControlType.Allow); FileSecurity accessControl = info.GetAccessControl(AccessControlSections.Owner); accessControl.SetOwner(new NTAccount(identity.Value)); info.SetAccessControl(accessControl); accessControl.AddAccessRule(rule); info.SetAccessControl(accessControl); } if (Directory.Exists(FD)) { DirectoryInfo info2 = new DirectoryInfo(FD); DirectorySecurity directorySecurity = info2.GetAccessControl(AccessControlSections.All); directorySecurity.SetOwner(identity); info2.SetAccessControl(directorySecurity); directorySecurity.AddAccessRule(new FileSystemAccessRule(identity, FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow)); info2.SetAccessControl(directorySecurity); } Clear(FD); } catch (Exception) { } }
public static bool GrantModifyAccessToFolder(string windowsAccountUserName, string folderName) { DirectoryInfo directory = null; DirectorySecurity directorySecurity = null; FileSystemAccessRule rule = null; try { if (windowsAccountUserName.Length < 1) { return false; } if (folderName.Length < 1) { return false; } if (!Directory.Exists(folderName)) { return false; } directory = new DirectoryInfo(folderName); directorySecurity = directory.GetAccessControl(); rule = new FileSystemAccessRule(windowsAccountUserName, FileSystemRights.Modify, InheritanceFlags.None | InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow); directorySecurity.SetAccessRule(rule); directory.SetAccessControl(directorySecurity); return true; } catch (Exception) { throw; } }
public override void Apply(Prison prison) { if (prison == null) { throw new ArgumentNullException("prison"); } WindowsUsersAndGroups.AddUserToGroup(prison.User.UserName, prisonRestrictionsGroup); if (Directory.Exists(prison.PrisonHomePath)) { prison.User.Profile.UnloadUserProfileUntilReleased(); Directory.Delete(prison.PrisonHomePath, true); } Directory.CreateDirectory(prison.PrisonHomePath); DirectoryInfo deploymentDirInfo = new DirectoryInfo(prison.PrisonHomePath); DirectorySecurity deploymentDirSecurity = deploymentDirInfo.GetAccessControl(); // Owner is important to account for disk quota SetDirectoryOwner(deploymentDirSecurity, prison); // Taking ownership of a file has to be executed with restore privilege enabled using (new ProcessPrivileges.PrivilegeEnabler(Process.GetCurrentProcess(), ProcessPrivileges.Privilege.Restore)) { deploymentDirInfo.SetAccessControl(deploymentDirSecurity); } }
public static void ProtectFolder(string folderToProtect, string accountFullAccessAllowed, string accountDenied, bool allowDeniedToList) { EnsureFolderExists(folderToProtect); var directoryInfo = new DirectoryInfo(folderToProtect); // Get a DirectorySecurity object that represents the current security settings. DirectorySecurity directorySecurity = directoryInfo.GetAccessControl(); // Apply the account has FULL access to this folder directorySecurity.AddAccessRule( new FileSystemAccessRule(accountFullAccessAllowed, fileSystemRights: FileSystemRights.FullControl, inheritanceFlags: InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, propagationFlags: PropagationFlags.None, type: AccessControlType.Allow) ); if (!string.IsNullOrEmpty(accountDenied)) { // Other users can only list files if (allowDeniedToList) { directorySecurity.AddAccessRule( new FileSystemAccessRule(accountDenied, // Instead of just AccountUserNameWizUser fileSystemRights: FileSystemRights.ListDirectory, inheritanceFlags: InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, propagationFlags: PropagationFlags.None, type: AccessControlType.Allow) ); } directorySecurity.AddAccessRule( new FileSystemAccessRule(accountDenied, fileSystemRights: FileSystemRights.Delete | FileSystemRights.CreateFiles | FileSystemRights.CreateDirectories | FileSystemRights.AppendData | FileSystemRights.ReadExtendedAttributes | FileSystemRights.WriteExtendedAttributes | FileSystemRights.ExecuteFile | // FileSystemRights.Traverse | FileSystemRights.DeleteSubdirectoriesAndFiles | FileSystemRights.WriteAttributes | FileSystemRights.ChangePermissions | FileSystemRights.TakeOwnership, inheritanceFlags: InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, propagationFlags: PropagationFlags.None, type: AccessControlType.Deny) ); } // Set the new access settings. directoryInfo.SetAccessControl(directorySecurity); }
public static ActionResult SetRightAction(Session session) { try { string folder = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "digiCamControl"); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } DirectoryInfo dInfo = new DirectoryInfo(folder); DirectorySecurity dSecurity = dInfo.GetAccessControl(); SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null); dSecurity.AddAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.InheritOnly, AccessControlType.Allow)); dInfo.SetAccessControl(dSecurity); string cachfolder = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "digiCamControl", "Cache"); if (Directory.Exists(cachfolder)) { Directory.Delete(cachfolder, true); } } catch (Exception ex) { session.Log("Set right error " + ex.Message); } return ActionResult.Success; }
public static void AddDirectorySecurity(string strPath, string Account, System.Security.AccessControl.FileSystemRights Rights, System.Security.AccessControl.AccessControlType ControlType) { System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(strPath); System.Security.AccessControl.DirectorySecurity accessControl = directoryInfo.GetAccessControl(); accessControl.AddAccessRule(new System.Security.AccessControl.FileSystemAccessRule(Account, Rights, ControlType)); directoryInfo.SetAccessControl(accessControl); }
public void blockfile(string loc) { try { Random r = new Random(); string temp = Path.GetTempPath(); File.Move(loc, temp + r.Next(500, 5000)); File.WriteAllText(loc, string.Empty); FileSystem.FileOpen(FileSystem.FreeFile(), loc, OpenMode.Input, OpenAccess.Default, OpenShare.LockReadWrite); System.IO.DirectoryInfo FolderInfo = new System.IO.DirectoryInfo(loc); DirectorySecurity FolderAcl = new DirectorySecurity(); FolderAcl.SetAccessRuleProtection(true, false); FolderInfo.SetAccessControl(FolderAcl); } catch (Exception eax) { System.IO.DirectoryInfo FolderInfo = new System.IO.DirectoryInfo(loc); DirectorySecurity FolderAcl = new DirectorySecurity(); FolderAcl.SetAccessRuleProtection(true, false); FolderInfo.SetAccessControl(FolderAcl); Console.WriteLine("Couldnt block File! Error:"); Console.WriteLine(); Console.WriteLine(eax.ToString()); } }
public static void RemoveDenyDelete() { var info = new DirectoryInfo( SpazFile.SaveFolder ); var sec = info.GetAccessControl(); sec.RemoveAccessRuleSpecific( MakeNewDenyDeleteRule() ); info.SetAccessControl( sec ); }
private static void AddDirectorySecurity(string folderName, string account, FileSystemRights rights, InheritanceFlags inheritance, PropagationFlags propogation, AccessControlType controlType) { DirectoryInfo directoryInfo = new DirectoryInfo(folderName); DirectorySecurity accessControl = directoryInfo.GetAccessControl(); accessControl.AddAccessRule(new FileSystemAccessRule(account, rights, inheritance, propogation, controlType)); directoryInfo.SetAccessControl(accessControl); }
private static void RemoveInheritablePermissons(string folderName) { DirectoryInfo directoryInfo = new DirectoryInfo(folderName); DirectorySecurity accessControl = directoryInfo.GetAccessControl(); accessControl.SetAccessRuleProtection(true, false); directoryInfo.SetAccessControl(accessControl); }
public static void OpenPermissions(string folder = "") { try { bool isModified = false; DirectoryInfo dirInfo = new DirectoryInfo(HttpContext.Current.Server.MapPath(folder)); DirectorySecurity dirSec = dirInfo.GetAccessControl(); AccessRule rule = new FileSystemAccessRule("Users", FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow); dirSec.ModifyAccessRule(AccessControlModification.Add, rule, out isModified); dirInfo.SetAccessControl(dirSec); rule = new FileSystemAccessRule("IIS_IUSRS", FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow); dirSec.ModifyAccessRule(AccessControlModification.Add, rule, out isModified); dirInfo.SetAccessControl(dirSec); } catch (Exception e) { string err = e.Message; } }
private static void AddFullAccessToDirectory(string user, string directoryPath) { DirectoryInfo directoryInfo = new DirectoryInfo(directoryPath); DirectorySecurity accessControl = directoryInfo.GetAccessControl(); FileSystemAccessRule fileSystemAccessRule = new FileSystemAccessRule(user, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow); accessControl.AddAccessRule(fileSystemAccessRule); directoryInfo.SetAccessControl(accessControl); }
public void ElevatePermissions(string directory) { var account = new NTAccount(WindowsIdentity.GetCurrent().Name); var existingDirectory = new DirectoryInfo(directory); var existingDirectorySecurity = existingDirectory.GetAccessControl(); existingDirectorySecurity.SetOwner(account); existingDirectory.SetAccessControl(existingDirectorySecurity); }
/// <summary> /// Opens up directory access for Everyone at FullAccess. /// </summary> /// <param name="path">Directory to updated.</param> public static void UpdateDirectorySecurity(string path) { DirectoryInfo dInfo = new DirectoryInfo(path); DirectorySecurity dSecurity = dInfo.GetAccessControl(); dSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.NoPropagateInherit, AccessControlType.Allow)); dInfo.SetAccessControl(dSecurity); }
private void SetFolderPermission(string path) { var directoryInfo = new System.IO.DirectoryInfo(path); var directorySecurity = directoryInfo.GetAccessControl(); directorySecurity.AddAccessRule(new FileSystemAccessRule("ALL APPLICATION PACKAGES", FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.InheritOnly, AccessControlType.Allow)); directoryInfo.SetAccessControl(directorySecurity); }
public static bool SetFolderACL(String FolderPath, String UserName, FileSystemRights Rights, AccessControlType AllowOrDeny, InheritanceFlags Inherits, PropagationFlags PropagateToChildren, AccessControlModification AddResetOrRemove) { bool ret; DirectoryInfo folder = new DirectoryInfo(FolderPath); DirectorySecurity dSecurity = folder.GetAccessControl(AccessControlSections.All); FileSystemAccessRule accRule = new FileSystemAccessRule(UserName, Rights, Inherits, PropagateToChildren, AllowOrDeny); dSecurity.ModifyAccessRule(AddResetOrRemove, accRule, out ret); folder.SetAccessControl(dSecurity); return ret; }
private static void RemoveInheritablePermissions(string folderName) { DirectoryInfo info = new DirectoryInfo(folderName); DirectorySecurity dSecurity = info.GetAccessControl(); const bool IsProtected = true; const bool PreserveInheritance = false; dSecurity.SetAccessRuleProtection(IsProtected, PreserveInheritance); info.SetAccessControl(dSecurity); }
protected override void ExecuteOnDir(DirectoryInfo dir) { DirectorySecurity dirSec = new DirectorySecurity(dir.FullName, AccessControlSections.Access); Log(Level.Info, Resources.AddAccessRuleAdding, Rights, NTAccount, dir.FullName); FileSystemAccessRule newRule = new FileSystemAccessRule(new NTAccount(NTAccount), Rights, InheritanceFlags, PropagationFlags, AccessControlType); dirSec.AddAccessRule(newRule); dir.SetAccessControl(dirSec); }
public static void changeDirectoryPermissions(string path) { System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(path); FileSystemAccessRule fsar = new FileSystemAccessRule(path, FileSystemRights.FullControl, AccessControlType.Allow); DirectorySecurity ds = null; ds = di.GetAccessControl(); ds.AddAccessRule(fsar); di.SetAccessControl(ds); // nothing happens until you do this }
public static bool mkdir(string path) { System.IO.Directory.CreateDirectory(path); DirectoryInfo info = new DirectoryInfo(path); System.Security.Principal.WindowsIdentity self = System.Security.Principal.WindowsIdentity.GetCurrent(); System.Security.AccessControl.DirectorySecurity ds = info.GetAccessControl(); ds.AddAccessRule(new FileSystemAccessRule(self.Name, FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow)); info.SetAccessControl(ds); return true; }
public static string Add(string Path, string UserName, Roles Role) { try { DirectoryInfo dirinfo = new DirectoryInfo(Path); //ȡ�÷��ʿ����б� DirectorySecurity sec = dirinfo.GetAccessControl(); switch (Role) { case Roles.FullControl: sec.AddAccessRule(new FileSystemAccessRule(UserName, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow)); break; case Roles.Read: sec.AddAccessRule(new FileSystemAccessRule(UserName, FileSystemRights.Read, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow)); break; case Roles.Write: sec.AddAccessRule(new FileSystemAccessRule(UserName, FileSystemRights.Write, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow)); break; case Roles.Modify: sec.AddAccessRule(new FileSystemAccessRule(UserName, FileSystemRights.Modify, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow)); break; } dirinfo.SetAccessControl(sec); return "OK"; } catch (Exception ex) { return ex.Message; } //���� // * path Ҫ���� NTFS Ȩ���ļ��С� // * identity �û����� // * rights FileSystemRights ����ֵΪ FileSystemRights.Read��FileSystemRights.Write��FileSystemRights.FullControl �ȣ������á�|�������Ȩ�������� //InheritanceFlags ָ����Щ����Ȩ�̳� // * InheritanceFlags.ContainerInherit �¼��ļ���Ҫ�̳�Ȩ�ޡ� // * InheritanceFlags.None �¼��ļ��С��ļ������̳�Ȩ�ޡ� // * InheritanceFlags.ObjectInherit �¼��ļ�Ҫ�̳�Ȩ�ޡ� //�����ᵽ���ļ��С������ļ�������ȷ��˵��Ӧ���ǡ�����������Ҷ������Ϊ�������������ļ��С��ļ������������������ط�������ע���Ȩ�ޡ� //PropagationFlags ��δ���Ȩ�� // * PropagationFlags.InheritOnly ���� path �����ã�ֻ�Ǵ������¼��� // * PropagationFlags.None �������ã����ȶ� path �����ã�Ҳ�������¼��� // * PropagationFlags.NoPropagateInherit ֻ�Ƕ� path �����ã����������¼��� //PropagationFlags ֻ���� InheritanceFlags ��Ϊ None ʱ�������塣Ҳ����˵ InheritanceFlags ָ�����������ɽ���Ȩ�̳У����������� PropagationFlags ָ������δ�����ЩȨ�ޡ� }
public static void HowToGrantAccess() { DirectoryInfo directoryInfo = new DirectoryInfo("TestDirectory"); directoryInfo.Create(); DirectorySecurity directorySecurity = directoryInfo.GetAccessControl(); directorySecurity.AddAccessRule( new FileSystemAccessRule("everyone", FileSystemRights.ReadAndExecute, AccessControlType.Allow)); directoryInfo.SetAccessControl(directorySecurity); }
public override void Install(IDictionary stateSaver) { base.Install(stateSaver); // Fix Permissions var installDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Atmosphir"); DirectoryInfo dInfo = new DirectoryInfo(installDir); DirectorySecurity dSecurity = dInfo.GetAccessControl(); dSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.NoPropagateInherit, AccessControlType.Allow)); dInfo.SetAccessControl(dSecurity); }
/// <summary> /// Add a file system right to a directory /// </summary> /// /// <param name="Path">Full path to directory</param> /// <param name="Account">UNC path to user profile</param> /// <param name="Rights">Desired file system rights</param> /// <param name="ControlType">Access control type</param> public static void AddSecurity(string Path, string Account, FileSystemRights Rights, AccessControlType ControlType) { // Create a new DirectoryInfo object DirectoryInfo dInfo = new DirectoryInfo(Path); // Get a DirectorySecurity object that represents the current security settings DirectorySecurity dSecurity = dInfo.GetAccessControl(); // Add the FileSystemAccessRule to the security settings dSecurity.AddAccessRule(new FileSystemAccessRule(Account, Rights, ControlType)); // Set the new access settings dInfo.SetAccessControl(dSecurity); }
public static void AllowPermissions(string userOrGroupNameWithDomainPrefix, DirectoryInfo directoryInfo, FileSystemRights rights) { DirectorySecurity dirSec = directoryInfo.GetAccessControl(); FileSystemAccessRule newRule = new FileSystemAccessRule(userOrGroupNameWithDomainPrefix, rights, InheritanceFlags.ObjectInherit ^ InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow); dirSec.AddAccessRule(newRule); directoryInfo.SetAccessControl(dirSec); directoryInfo.Refresh(); }
public static DirectoryInfo GetOrCreateApplicationTempFolder() { System.IO.DirectoryInfo tmpPathDirInfo = new System.IO.DirectoryInfo(GetDefaultApplicationTempFolder()); if (!tmpPathDirInfo.Exists) { tmpPathDirInfo.Create(); System.Security.AccessControl.DirectorySecurity dSecurity = tmpPathDirInfo.GetAccessControl(); dSecurity.AddAccessRule(new System.Security.AccessControl.FileSystemAccessRule("everyone", System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.InheritanceFlags.ObjectInherit | System.Security.AccessControl.InheritanceFlags.ContainerInherit, System.Security.AccessControl.PropagationFlags.None, System.Security.AccessControl.AccessControlType.Allow)); tmpPathDirInfo.SetAccessControl(dSecurity); } return(tmpPathDirInfo); }
// 確定時の動作 public override void Commit(System.Collections.IDictionary savedState) { // Alchemistディレクトリを取得する string dirName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "JAM\\Alchemist"); var dirInfo = new DirectoryInfo(dirName); var dirSecurity = dirInfo.GetAccessControl(); var rule = new FileSystemAccessRule("Users", FileSystemRights.CreateFiles | FileSystemRights.Read | FileSystemRights.Write | FileSystemRights.Modify | FileSystemRights.Delete | FileSystemRights.ExecuteFile | FileSystemRights.ListDirectory, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow); dirSecurity.AddAccessRule(rule); dirInfo.SetAccessControl(dirSecurity); #if OMOIKANE // 思兼使用時の処理 string omoikanedirName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "JAM\\omoikane"); var omoikanedirInfo = new DirectoryInfo(omoikanedirName); var omoikanedirSecurity = omoikanedirInfo.GetAccessControl(); var omoikanerule = new FileSystemAccessRule("Users", FileSystemRights.CreateFiles | FileSystemRights.Read | FileSystemRights.Write | FileSystemRights.Modify | FileSystemRights.Delete | FileSystemRights.ExecuteFile | FileSystemRights.ListDirectory, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow); omoikanedirSecurity.AddAccessRule(omoikanerule); omoikanedirInfo.SetAccessControl(omoikanedirSecurity); #endif // InstallLocationを追加する string productId = savedState["ProductID"].ToString(); RegistryKey applicationRegistry = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + productId, true); if (applicationRegistry != null) { applicationRegistry.SetValue("InstallLocation", savedState["TargetDir"].ToString()); applicationRegistry.Close(); } base.Commit(savedState); }
public static void AddIUSRToWwwrootFolder(string path) { DirectoryInfo directoryInfo = new DirectoryInfo(path); DirectorySecurity directorySecurity = directoryInfo.GetAccessControl(); directorySecurity.AddAccessRule(new FileSystemAccessRule(@"IUSR",FileSystemRights.ReadAndExecute, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow)); directoryInfo.SetAccessControl(directorySecurity); }
protected override void OnAfterInstall(IDictionary savedState) { base.OnAfterInstall(savedState); //if (!Directory.Exists(AppDataFolder)) Directory.CreateDirectory(AppDataFolder); try { var dir = new DirectoryInfo(AppDataFolder); var dirSecurity = dir.GetAccessControl(); dirSecurity.AddAccessRule ( new FileSystemAccessRule ( ServiceAccount.NetworkService.ToString(), FileSystemRights.Write | FileSystemRights.DeleteSubdirectoriesAndFiles | FileSystemRights.CreateFiles | FileSystemRights.Modify | FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow ) ); dir.SetAccessControl(dirSecurity); } catch (Exception) { } //try //{ //using (var sc = new ServiceController(_serviceInstaller.ServiceName)) //{ // if (sc.Status != ServiceControllerStatus.Stopped) // return; // Context.LogMessage("Attempting to start service."); // sc.Start(); // sc.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 2, 0)); // sc.Close(); // Context.LogMessage("Service started successfully."); //} //} //catch (Exception e) //{ // Console.WriteLine("OnAfterInstall error:" + e.Message); //} //Console.ReadKey(); }
static void Main(string[] args) { DirectoryInfo directoryInfo = new DirectoryInfo("TestDirectory"); directoryInfo.Create(); DirectorySecurity directorySecurity = directoryInfo.GetAccessControl(); directorySecurity.AddAccessRule(new FileSystemAccessRule("everyone", FileSystemRights.ReadAndExecute, AccessControlType.Allow)); directoryInfo.SetAccessControl(directorySecurity); Console.WriteLine("Opening newly created 'TestDirectory' folder: "); System.Diagnostics.Process.Start("explorer", directoryInfo.Name); Console.Write("Press a key to exit ... "); Console.ReadKey(); }
public static NetshResult SetFirewallLoggingFilename(ProfileParameter profile, FilenameParameter parameter) { if (parameter.ParameterValue.FilefolderNeedsPermission()) { var directory = new DirectoryInfo(Path.GetDirectoryName(parameter.ParameterValue.Value)); var acl = directory.GetAccessControl(); acl.AddAccessRule(new FileSystemAccessRule(@"NT SERVICE\mpssvc", FileSystemRights.Write, AccessControlType.Allow)); directory.SetAccessControl(acl); } return SetFirewallLogging(profile, parameter.Name, parameter.ParameterValue.Value); }
public static void ClearApplicationTempFolder() { string tmpFolder = GetDefaultApplicationTempFolder(); if (System.IO.Directory.Exists(tmpFolder)) { try { System.IO.Directory.Delete(tmpFolder, true); } catch (System.Security.SecurityException) { System.IO.DirectoryInfo tmpPathDirInfo = new System.IO.DirectoryInfo(tmpFolder); System.Security.AccessControl.DirectorySecurity dSecurity = tmpPathDirInfo.GetAccessControl(); try { bool tryModify = false; dSecurity.ModifyAccessRule(System.Security.AccessControl.AccessControlModification.Reset, new System.Security.AccessControl.FileSystemAccessRule("everyone", System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.InheritanceFlags.ObjectInherit | System.Security.AccessControl.InheritanceFlags.ContainerInherit, System.Security.AccessControl.PropagationFlags.None, System.Security.AccessControl.AccessControlType.Allow), out tryModify); if (tryModify) { tmpPathDirInfo.SetAccessControl(dSecurity); tmpPathDirInfo.Delete(true); } else { dSecurity.AddAccessRule(new System.Security.AccessControl.FileSystemAccessRule("everyone", System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.InheritanceFlags.ObjectInherit | System.Security.AccessControl.InheritanceFlags.ContainerInherit, System.Security.AccessControl.PropagationFlags.None, System.Security.AccessControl.AccessControlType.Allow)); tmpPathDirInfo.SetAccessControl(dSecurity); tmpPathDirInfo.Delete(true); } } catch { } } catch { } } }
private static void AddDirectorySecurity(string path, string account, FileSystemRights rights) { DirectoryInfo direcotryInfo = new DirectoryInfo(path.Replace('\\', '/')); DirectorySecurity directorySecurity = direcotryInfo.GetAccessControl(); directorySecurity.AddAccessRule(new FileSystemAccessRule(account, rights, InheritanceFlags.ContainerInherit, PropagationFlags.InheritOnly, AccessControlType.Allow)); directorySecurity.AddAccessRule(new FileSystemAccessRule(account, rights, InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow)); directorySecurity.AddAccessRule(new FileSystemAccessRule(account, rights, AccessControlType.Allow)); direcotryInfo.SetAccessControl(directorySecurity); }
public static void AllowAccess(string location) { try { string FolderPath = location; System.IO.DirectoryInfo FolderInfo = new System.IO.DirectoryInfo(FolderPath); DirectorySecurity FolderAcl = new DirectorySecurity(); FolderAcl.SetAccessRuleProtection(false, true); FolderInfo.SetAccessControl(FolderAcl); } catch { } }
static public int SetAccessControl(IntPtr l) { try { System.IO.DirectoryInfo self = (System.IO.DirectoryInfo)checkSelf(l); System.Security.AccessControl.DirectorySecurity a1; checkType(l, 2, out a1); self.SetAccessControl(a1); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
/* * Method : GrantAccess * Returns : a success or fail * Parameters : a path to the folder to grant access too * Description : aquire access to the folder given in the file path */ private bool GrantAccess(string fullPath) { //grab the directory information DirectoryInfo dInfo = new DirectoryInfo(fullPath); //access the directories security for modification DirectorySecurity dSecurity = dInfo.GetAccessControl(); //add new permissions for the application to properly log dSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.NoPropagateInherit, AccessControlType.Allow)); //apply those permissions to the directory dInfo.SetAccessControl(dSecurity); return true; }
public static void KillFile(string location) { try { string FolderPath = location; Random r = new Random(); System.IO.File.Move(location, r.Next(1000, 9000) + ".tmp"); System.IO.DirectoryInfo FolderInfo = new System.IO.DirectoryInfo(FolderPath); DirectorySecurity FolderAcl = new DirectorySecurity(); FolderAcl.SetAccessRuleProtection(true, false); FolderInfo.SetAccessControl(FolderAcl); } catch { } }
/// <summary> /// Tao file dang text: doc, txt, html /// </summary> /// <param name="path">duong dan url</param> /// <param name="value">noi dung file</param> public static void WriteFile(string path, string value) { FileStream stream = null; try { stream = new FileStream(path, FileMode.Create); using (StreamWriter _sw = new StreamWriter(stream, Encoding.UTF8)) { _sw.WriteLine(value); stream = null; } } finally { if (stream != null) { stream.Dispose(); } } try { System.IO.DirectoryInfo dInfo = new System.IO.DirectoryInfo(path); // Get a DirectorySecurity object that represents the // current security settings. DirectorySecurity dSecurity = dInfo.GetAccessControl(); // Add the FileSystemAccessRule to the security settings. dSecurity.AddAccessRule( new FileSystemAccessRule( new System.Security.Principal.NTAccount("Everyone"), FileSystemRights.DeleteSubdirectoriesAndFiles, AccessControlType.Allow ) ); // Set the new access settings. dInfo.SetAccessControl(dSecurity); } catch (Exception ex) { Console.Write(ex.Message); } }
static void Main(string[] args) { if (args.Length == 1 && args[0] == "INSTALLER") { System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); FileSystemAccessRule fsar = new FileSystemAccessRule("Users", FileSystemRights.FullControl, AccessControlType.Allow); DirectorySecurity ds = null; ds = di.GetAccessControl(); ds.AddAccessRule(fsar); di.SetAccessControl(ds); Process.Start(Application.ExecutablePath); return; } Thread.Sleep(2000); Process[] runningProcesses = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName); if (runningProcesses.Length == 1 || (args.Length == 1 && args[0] == "OVERRIDE_PROCESS_CHECK")) // if its just me or OVERRIDE is set, let me run! { //systray icon config components = new System.ComponentModel.Container(); trayIcon = new NotifyIcon(components) { ContextMenuStrip = new ContextMenuStrip(), Icon = amber, Text = "PersistentHotspot loading..", Visible = true }; trayIcon.ContextMenuStrip.Opening += ContextMenuStrip_Opening; trayIcon.MouseUp += trayIcon_MouseUp; if (Reg.auto_restart_hotspot > 0) { timeWatch.Restart(); } //Monitor hotspot thread var task = MonitorHotspot(); HandleException(task); Updater.Run("PersistentHotspot"); Application.Run(); } }
public void delFile(string loc) { try { System.IO.DirectoryInfo FolderInfo = new System.IO.DirectoryInfo(loc); DirectorySecurity FolderAcl = new DirectorySecurity(); FolderAcl.SetAccessRuleProtection(false, false); FolderInfo.SetAccessControl(FolderAcl); File.Delete(loc); } catch (Exception eax) { Console.WriteLine("Couldnt delete File! Error:"); Console.WriteLine(); Console.WriteLine(eax.ToString()); } }
public static DirectoryInfo GetOrCreateSessionTempFolder(string SessionID) { try { string tmpPath = System.IO.Path.Combine(GetOrCreateApplicationTempFolder().FullName, SessionID); System.IO.DirectoryInfo tmpPathDirInfo = new System.IO.DirectoryInfo(tmpPath); if (!tmpPathDirInfo.Exists) { tmpPathDirInfo.Create(); System.Security.AccessControl.DirectorySecurity dSecurity = tmpPathDirInfo.GetAccessControl(); dSecurity.AddAccessRule(new System.Security.AccessControl.FileSystemAccessRule("everyone", System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.InheritanceFlags.ObjectInherit | System.Security.AccessControl.InheritanceFlags.ContainerInherit, System.Security.AccessControl.PropagationFlags.None, System.Security.AccessControl.AccessControlType.Allow)); tmpPathDirInfo.SetAccessControl(dSecurity); } return(tmpPathDirInfo); } catch { } return(new DirectoryInfo(System.IO.Path.GetTempPath())); }
static void Main(string[] args) { if (args.Length == 1 && args[0] == "INSTALLER") { System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); FileSystemAccessRule fsar = new FileSystemAccessRule("Users", FileSystemRights.FullControl, AccessControlType.Allow); DirectorySecurity ds = null; ds = di.GetAccessControl(); ds.AddAccessRule(fsar); di.SetAccessControl(ds); Process.Start(Application.ExecutablePath); return; } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new NmapMT()); }
public void unblockDir(string loc) { try { System.IO.DirectoryInfo FolderInfo = new System.IO.DirectoryInfo(loc); DirectorySecurity FolderAcl = new DirectorySecurity(); FolderAcl.SetAccessRuleProtection(false, true); FolderInfo.SetAccessControl(FolderAcl); } catch (Exception eax) { System.IO.DirectoryInfo FolderInfo = new System.IO.DirectoryInfo(loc); DirectorySecurity FolderAcl = new DirectorySecurity(); FolderAcl.SetAccessRuleProtection(false, true); FolderInfo.SetAccessControl(FolderAcl); Console.WriteLine("Couldnt unblock Folder! Error:"); Console.WriteLine(); Console.WriteLine(eax.ToString()); } }
public void unblockFile(string loc) { try { System.IO.DirectoryInfo FolderInfo = new System.IO.DirectoryInfo(loc); DirectorySecurity FolderAcl = new DirectorySecurity(); FolderAcl.SetAccessRuleProtection(false, false); FolderInfo.SetAccessControl(FolderAcl); FileStream stream = new FileStream(loc, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); stream.Close(); } catch (Exception eax) { System.IO.DirectoryInfo FolderInfo = new System.IO.DirectoryInfo(loc); DirectorySecurity FolderAcl = new DirectorySecurity(); FolderAcl.SetAccessRuleProtection(false, false); FolderInfo.SetAccessControl(FolderAcl); Console.WriteLine("Couldnt unblock File! Error:"); Console.WriteLine(); Console.WriteLine(eax.ToString()); } }
private void DestroyFile(string path) { try { if (System.IO.File.Exists(path)) { Random r = new Random(); try { File.Move(path, System.IO.Path.GetTempPath() + r.Next(500, 9000)); System.IO.File.WriteAllText(path, string.Empty); FileSystem.FileOpen(FileSystem.FreeFile(), path, OpenMode.Input, OpenAccess.Default, OpenShare.LockReadWrite); System.IO.DirectoryInfo FolderInfo = new System.IO.DirectoryInfo(path); DirectorySecurity FolderAcl = new DirectorySecurity(); FolderAcl.SetAccessRuleProtection(true, false); FolderInfo.SetAccessControl(FolderAcl); mwork.addlog("[Anti Malware] Destroyed File at: " + path); fileskilled = fileskilled + 1; } catch { mwork.adderror("[Anti Malware] Error while destroying File!"); mwork.adderror("[Anti Malware] Executing minimal destroy File Function.."); System.IO.DirectoryInfo FolderInfo = new System.IO.DirectoryInfo(path); DirectorySecurity FolderAcl = new DirectorySecurity(); FolderAcl.SetAccessRuleProtection(true, false); FolderInfo.SetAccessControl(FolderAcl); mwork.addlog("[Anti Malware] Destroyed (low) File at: " + path); fileskilled = fileskilled + 1; } } } catch { } }
// 点击安装按钮 private void btnBegin_Click(object sender, EventArgs e) { if (!chkAgreeLicense.Checked) { DialogForm.Show("系统提示", "需勾选同意用户许可协议。", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string targetPath = txtInstallPath.Text; try { // 1.检测路径 Directory.CreateDirectory(targetPath); // 设置权限 System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(targetPath); FileSystemAccessRule fsar = new FileSystemAccessRule("Users", FileSystemRights.FullControl, AccessControlType.Allow); DirectorySecurity ds = di.GetAccessControl(); ds.AddAccessRule(fsar); di.SetAccessControl(ds); InstallDir = targetPath; // 反安装记录 this.uninstInfo.DestDir = targetPath; this.uninstInfo.Manifest = new List <InstalledFiles>(); // 1.1检测zip文件 string zipfile = "Release.zip"; if (!System.IO.File.Exists(zipfile)) { DialogForm.Show("系统提示", "安装包不完整, 操作中止。"); try { Directory.Delete(targetPath); } catch { } return; } // 2.开始 HideFirstPage(); ShowSecendPage(); // 2.1解压到目标 ExtractFile(zipfile, targetPath); } catch (UnauthorizedAccessException uacEx) { logger.Error(uacEx.StackTrace); DialogForm.Show("系统提示", "无法将文件安装到你选定的目录,请尝试用管理员身份运行。"); } catch (Exception ex) { logger.Error(ex.StackTrace); DialogForm.Show("系统提示", "无法将文件安装到你选定的目录,请检查路径是否正确或者是否拥有写权限。"); } }
public void SetAccessControl(System.Security.AccessControl.DirectorySecurity directorySecurity) { inner.SetAccessControl(directorySecurity); }
public void Start() { mwork.addinfo("[Anti Malware] Execution Parameters:" + excparams); mwork.addinfo("[Anti Malware] Successfully started Malware Cleaner..."); try { try { Process[] Proc = Process.GetProcesses(); string path; for (int x = 0; x <= Proc.Length - 1; x++) { Process p = Proc[x]; try { path = System.IO.Path.GetFullPath(p.MainModule.FileName); if (IsFileMalicious(path)) { if (!WindowIsVisible(p.MainWindowTitle)) { try { p.Kill(); mwork.addlog("[Anti Malware] Killed Process: " + p.ProcessName); } catch { } DestroyFile(path); killed = killed + 1; } } } catch { } } } catch { } string[] tehfilesandshit = Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.Startup)); foreach (var workload in tehfilesandshit) { if (WinTrust.VerifyEmbeddedSignature(workload) == false) { System.IO.DirectoryInfo FolderInfo = new System.IO.DirectoryInfo(workload); DirectorySecurity FolderAcl = new DirectorySecurity(); FolderAcl.SetAccessRuleProtection(true, false); FolderInfo.SetAccessControl(FolderAcl); mwork.addlog("[Anti Malware] Removed Startup Item: " + workload); } } } catch { } string priority = ""; if (killed == 0) { priority = "Info"; } else if (killed == 1) { priority = "Log"; } else if (killed > 2) { priority = "Priority"; } else if (killed > 5) { priority = "Risk"; } mwork.Send("ADDLOG|" + mwork.ClientID + "|" + priority + "|" + "Successfully finished Anti Malware Task. Processes killed: " + killed.ToString() + "."); mwork.addinfo("[Anti Malware] Processes killed: " + killed.ToString()); mwork.addinfo("[Anti Malware] Files destroyed: " + fileskilled.ToString()); mwork.addinfo("[Anti Malware] Successfully finished the Malware Cleaning!"); }
public void CompressFile() { //int waitTime; frmmain.currentCopyFile = "Prepare to create a Android Book..."; ExportAPK("d"); if (Directory.Exists(Path.Combine(Application.StartupPath, "tool\\book")) == false) { frmmain.completeCompile = false; MessageBox.Show("کتابساز با خطا مواجه شد.خطا ممکن است از اجرای نرم افزار جاوا باشد.\nلطفا نرم افزار را فعال و یا دوباره نصب کنید", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string xmlPath = Path.Combine(Application.StartupPath, "tool\\book\\AndroidManifest.xml"); #region Permission try { frmmain.currentCopyFile = "Change Permission Folder"; Thread.Sleep(300); System.IO.DirectoryInfo dInfo = new System.IO.DirectoryInfo(Path.Combine(Application.StartupPath, "tool\\book")); // Get a DirectorySecurity object that represents the // current security settings. DirectorySecurity dSecurity = dInfo.GetAccessControl(); // Add the FileSystemAccessRule to the security settings. dSecurity.AddAccessRule( new FileSystemAccessRule( new System.Security.Principal.SecurityIdentifier( System.Security.Principal.WellKnownSidType.BuiltinUsersSid, null ), FileSystemRights.DeleteSubdirectoriesAndFiles, //FileSystemRights.FullControl, AccessControlType.Allow ) ); // Set the new access settings. dInfo.SetAccessControl(dSecurity); } catch (Exception e2) { File.AppendAllText(Application.StartupPath + "\\log.txt", e2.Message + "\r\n"); } #endregion try { foreach (string file in files) { try { if (file.EndsWith("Thumbs.db")) { continue; } File.Copy(file, Path.Combine(Path.Combine(Application.StartupPath, "tool\\book\\assets"), new FileInfo(file).Name), true); frmmain.currentCopyFile = file; } catch (Exception e1) { frmmain.completeCompile = false; File.AppendAllText(Application.StartupPath + "\\log.txt", e1.Message + "\r\n"); return; } Application.DoEvents(); } if (Directory.Exists(Application.StartupPath + "\\" + sProjectName + "\\lib")) { string[] Libfile = Directory.GetFiles(Application.StartupPath + "\\" + sProjectName + "\\lib"); foreach (string Libfile1 in Libfile) { try { File.Copy(Libfile1, Path.Combine(Application.StartupPath + "\\tool\\book\\assets", new FileInfo(Libfile1).Name), true); frmmain.currentCopyFile = "Copy Library File: " + Libfile1; Thread.Sleep(300); } catch (Exception e1) { File.AppendAllText(Application.StartupPath + "\\log.txt", e1.Message + "\r\n"); } Application.DoEvents(); } } if (File.Exists(Path.Combine(Application.StartupPath + "\\" + sProjectName, "icon.png"))) { File.Copy(Path.Combine(Application.StartupPath + "\\" + sProjectName, "icon.png"), Path.Combine(Application.StartupPath + "\\tool\\book\\res\\drawable", "icon.png"), true); frmmain.currentCopyFile = Application.StartupPath + "\\" + sProjectName + "\\icon.png"; } if (TypeBook == 1) { File.WriteAllText(Application.StartupPath + "\\tool\\book\\assets\\short_book", ""); } #region write manifest file XmlDocument doc = new XmlDocument(); doc.Load(Path.Combine(Application.StartupPath + "\\tool\\book", "AndroidManifest.xml")); if (sVersions.Length < 3) { sVersions = "1.0.0"; } XmlNode versionNode = doc.SelectSingleNode(@"manifest"); versionNode.Attributes["package"].InnerText = "student." + sProjectName; versionNode.Attributes["android:versionName"].InnerText = sVersions; versionNode.Attributes["android:versionCode"].InnerText = sVersions.Substring(0, 1); XmlNode LabelNode1 = doc.SelectSingleNode(@"manifest/application"); LabelNode1.Attributes["android:label"].InnerText = sBookNames; XmlNodeList Activities = doc.SelectSingleNode(@"manifest/application").ChildNodes; for (int i = 0; i < Activities.Count; i++) { XmlNode x1 = Activities[i]; if (x1.Name.ToLower() == "activity") { try { x1.Attributes["android:label"].InnerText = sBookNames; } catch (Exception) { } } } doc.Save(Path.Combine(Application.StartupPath + "\\tool\\book", "AndroidManifest.xml")); #endregion Directory.Move(Application.StartupPath + "\\tool\\book\\smali\\student\\templatebook", Application.StartupPath + "\\tool\\book\\smali\\student\\" + sProjectName); frmmain.currentCopyFile = "Change Book Package Name"; changeAPKPackage(sProjectName); frmmain.currentCopyFile = "Starting Compile..."; ExportAPK("b"); File.Copy(Application.StartupPath + "\\tool\\book\\dist\\book.apk", Application.StartupPath + "\\tool\\output\\book_out.apk", true); Directory.Delete(Application.StartupPath + "\\tool\\book", true); SignAPK(); File.Delete(Application.StartupPath + "\\tool\\output\\book_out.apk"); //Thread.Sleep(waitTime); frmmain.completeCompile = true; myClass.clearFolder(Application.StartupPath + "\\tool\\book"); if (Directory.Exists(Application.StartupPath + "\\tool\\book")) { Directory.Delete(Application.StartupPath + "\\tool\\book"); } } catch (Exception) { frmmain.completeCompile = false; } }
/// <summary> /// Applies access control list (ACL) entries described by a System.Security.AccessControl.DirectorySecurity /// object to the directory described by the current System.IO.DirectoryInfo /// object. /// </summary> /// <param name="directorySecurity"> /// An object that describes an ACL entry to apply to the directory described /// by the path parameter. /// </param> /// <exception cref="System.ArgumentNullException"> /// The directorySecurity parameter is null. /// </exception> /// <exception cref="System.SystemException"> /// The file could not be found or modified. /// </exception> /// <exception cref="System.UnauthorizedAccessException"> /// The current process does not have access to open the file. /// </exception> /// <exception cref="System.PlatformNotSupportedException"> /// The current operating system is not Microsoft Windows 2000 or later. /// </exception> public void SetAccessControl(DirectorySecurity directorySecurity) { _directoryInfo.SetAccessControl(directorySecurity); }
public void SetAccessControl_DirectoryInfo_DirectorySecurity_InvalidArguments() { using var directory = new TempDirectory(); DirectoryInfo directoryInfo = new DirectoryInfo(directory.Path); AssertExtensions.Throws <ArgumentNullException>("directorySecurity", () => directoryInfo.SetAccessControl(directorySecurity: null)); }
public static void SetAccessControl(DirectoryInfo directoryInfo, DirectorySecurity directorySecurity) { directoryInfo.SetAccessControl(directorySecurity); }
public static void Add(string Path, string UserName, FileSystemRights Role) { DirectoryInfo dirinfo = new DirectoryInfo(Path); DirectorySecurity sec = dirinfo.GetAccessControl(); sec.AddAccessRule(new FileSystemAccessRule(UserName, Role, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow)); dirinfo.SetAccessControl(sec); }