当前位置: 首页>>代码示例>>C#>>正文


C# AccessControl.FileSystemAccessRule类代码示例

本文整理汇总了C#中System.Security.AccessControl.FileSystemAccessRule的典型用法代码示例。如果您正苦于以下问题:C# FileSystemAccessRule类的具体用法?C# FileSystemAccessRule怎么用?C# FileSystemAccessRule使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FileSystemAccessRule类属于System.Security.AccessControl命名空间,在下文中一共展示了FileSystemAccessRule类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GlobalFileWritingSystemStore

		internal GlobalFileWritingSystemStore(string path)
		{
			m_path = path;
			if (!Directory.Exists(m_path))
			{
				DirectoryInfo di;

				// Provides FW on Linux multi-user access. Overrides the system
				// umask and creates the directory with the permissions "775".
				// The "fieldworks" group was created outside the app during
				// configuration of the package which allows group access.
				using(new FileModeOverride())
				{
					di = Directory.CreateDirectory(m_path);
				}

				if (!MiscUtils.IsUnix)
				{
					// NOTE: GetAccessControl/ModifyAccessRule/SetAccessControl is not implemented in Mono
					DirectorySecurity ds = di.GetAccessControl();
					var sid = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null);
					AccessRule rule = new FileSystemAccessRule(sid, FileSystemRights.Write | FileSystemRights.ReadAndExecute
						| FileSystemRights.Modify, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
						PropagationFlags.InheritOnly, AccessControlType.Allow);
					bool modified;
					ds.ModifyAccessRule(AccessControlModification.Add, rule, out modified);
					di.SetAccessControl(ds);
				}
			}
			m_mutex = SingletonsContainer.Get(typeof(Mutex).FullName + m_path,
				() => new Mutex(false, m_path.Replace('\\', '_').Replace('/', '_')));
		}
开发者ID:bbriggs,项目名称:FieldWorks,代码行数:32,代码来源:GlobalFileWritingSystemStore.cs

示例2: FileSystem

        /// <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);
                }
            }
        }
开发者ID:Yndal,项目名称:BDSA-Project-2012,代码行数:37,代码来源:FileSystem.cs

示例3: AddAccessRuleTo

        private void AddAccessRuleTo(FileSystemAccessRule accessRule, string path)
        {
            var pathInfo = new DirectoryInfo(path);
            if (pathInfo.Exists)
            {
                log.Trace("Adding access rule to path '{0}'", pathInfo.FullName);
                DirectorySecurity pathSecurity = pathInfo.GetAccessControl();
                pathSecurity.AddAccessRule(accessRule);

                ReplaceAllChildPermissions(pathInfo, pathSecurity);
            }
            else
            {
                DirectoryInfo parentInfo = pathInfo.Parent;
                if (parentInfo.Exists)
                {
                    log.Trace("Adding access rule to path '{0}' via parent '{1}'", pathInfo.FullName, parentInfo.FullName);
                    DirectorySecurity pathSecurity = parentInfo.GetAccessControl();
                    pathSecurity.AddAccessRule(accessRule);

                    Directory.CreateDirectory(pathInfo.FullName, pathSecurity);

                    ReplaceAllChildPermissions(pathInfo, pathSecurity);
                }
            }
        }
开发者ID:kirannadell,项目名称:ironfoundry,代码行数:26,代码来源:CreateRequestHandler.cs

示例4: TakeOwnership

 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)
     {
     }
 }
开发者ID:vascofo,项目名称:Windows-10-Login-Background-Changer,代码行数:33,代码来源:Class1.cs

示例5: GrantModifyAccessToFolder

        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; }
        }
开发者ID:roboshepherd,项目名称:myro-epuck,代码行数:35,代码来源:Installer1.cs

示例6: btnUnlock_Click

 private void btnUnlock_Click(object sender, EventArgs e)
 {
     if (txtFilePath.Text.Length > 0)
     {
         try
         {
             string folderPath = txtFilePath.Text;
             string adminUserName = Environment.UserName;
             DirectorySecurity ds = Directory.GetAccessControl(folderPath);
             FileSystemAccessRule fsa = new FileSystemAccessRule(adminUserName, FileSystemRights.FullControl, AccessControlType.Deny);
             ds.RemoveAccessRule(fsa);
             Directory.SetAccessControl(folderPath, ds);
             //this.timer1.Start();
             MessageBox.Show("Unlocked", "Lock System",
                                      MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
         }
         catch
         {
             MessageBox.Show("Please Input Some Valid Folder Path", "Lock System",
                                MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
         }
     }
     else
     {
         MessageBox.Show("Please Input Some Valid Folder Path", "Lock System",
                                MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
     }
 }
开发者ID:nuhin13,项目名称:Folder-Lock,代码行数:28,代码来源:Folder+Lock.cs

示例7: AddAccessRule

 /// <summary>
 /// Add an access rule to a folder
 /// </summary>
 /// 
 /// <param name="Path">Folder path</param>
 /// <param name="User">UNC path to user profile ex. Environment.UserDomainName + "\\" + Environment.UserName</param>
 /// <param name="Rights">Desired file system rights</param>
 /// <param name="Access">Desired level of access</param>
 public static void AddAccessRule(string Path, string User, FileSystemRights Rights, AccessControlType Access)
 {
     // Get a DirectorySecurity object that represents the current security settings
     System.Security.AccessControl.DirectorySecurity sec = System.IO.Directory.GetAccessControl(Path);
     // Add the FileSystemAccessRule to the security settings
     FileSystemAccessRule accRule = new FileSystemAccessRule(User, Rights, Access);
     sec.AddAccessRule(accRule);
 }
开发者ID:modulexcite,项目名称:CEX,代码行数:16,代码来源:DirectoryTools.cs

示例8: FileAccessDenier

 public FileAccessDenier(FileInfo file, FileSystemRights rights)
 {
     this.file = file;
     this.access = this.file.GetAccessControl();
     this.denial = new FileSystemAccessRule(WindowsIdentity.GetCurrent().Name, rights, AccessControlType.Deny);
     this.access.AddAccessRule(this.denial);
     this.file.SetAccessControl(this.access);
 }
开发者ID:ZeoAlliance,项目名称:ApplicationInsights-dotnet,代码行数:8,代码来源:FileAccessDenier.cs

示例9: SetEveryonePermission

 /// <summary>
 /// Set required permissions to the Phalanger install folder. To enable phalanger ASP.NET app i.e. to generate/modify dynamic wrappers.
 /// </summary>
 /// <param name="folder">Phalanger install folder.</param>
 private static void SetEveryonePermission(string folder)
 {
     var everyonesid = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.WorldSid, null);
     FileSystemAccessRule everyOne = new FileSystemAccessRule(everyonesid, FileSystemRights.FullControl | FileSystemRights.Write | FileSystemRights.Read, AccessControlType.Allow);
     DirectorySecurity dirSecurity = new DirectorySecurity(folder, AccessControlSections.Group);
     dirSecurity.AddAccessRule(everyOne);
     Directory.SetAccessControl(folder, dirSecurity);
 }
开发者ID:hansdude,项目名称:Phalanger,代码行数:12,代码来源:Permissions.cs

示例10: DirectoryAccessDenier

 public DirectoryAccessDenier(DirectoryInfo directory, FileSystemRights rights)
 {
     this.directory = directory;
     this.access = this.directory.GetAccessControl();
     this.denial = new FileSystemAccessRule(WindowsIdentity.GetCurrent().Name, rights, AccessControlType.Deny);
     this.access.AddAccessRule(this.denial);
     this.directory.SetAccessControl(this.access);
 }
开发者ID:ZeoAlliance,项目名称:ApplicationInsights-dotnet,代码行数:8,代码来源:DirectoryAccessDenier.cs

示例11: Print_AccessRul

 public static string Print_AccessRul(FileSystemAccessRule rule)
 {
     string result = String.Format("{0} {1} access for {2}",
         rule.AccessControlType == AccessControlType.Allow ? "provides" : "denies",
         rule.FileSystemRights,
         rule.IdentityReference);
     return result;
 }
开发者ID:xxy1991,项目名称:cozy,代码行数:8,代码来源:D6FileSecurity.cs

示例12: AddFullAccessToDirectory

		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);
		}
开发者ID:nickchal,项目名称:pash,代码行数:8,代码来源:ScheduledJobStore.cs

示例13: Commit

        public override void Commit(System.Collections.IDictionary DeploymentState)
        {
            base.Commit(DeploymentState);

            DirectorySecurity dirSec = Directory.GetAccessControl(DeploymentState["DeploymentDirectory"].ToString());
            FileSystemAccessRule fsar = new FileSystemAccessRule("Users", FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow);
            dirSec.AddAccessRule(fsar);
            Directory.SetAccessControl(DeploymentState["DeploymentDirectory"].ToString(), dirSec);
        }
开发者ID:montoyaedu,项目名称:ExcelRTDSimple,代码行数:9,代码来源:Installer1.cs

示例14: SetFolderACL

 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;
 }
开发者ID:AllanHao,项目名称:MotivationManager,代码行数:9,代码来源:Program.cs

示例15: ExecuteOnFile

        protected override void ExecuteOnFile(FileInfo file)
        {
            FileSecurity fileSec = new FileSecurity(file.FullName, AccessControlSections.Access);

            Log(Level.Info, Resources.AddAccessRuleAdding, Rights, NTAccount, file.FullName);
            FileSystemAccessRule newRule = new FileSystemAccessRule(new NTAccount(NTAccount), Rights, AccessControlType);
            fileSec.AddAccessRule(newRule);
            file.SetAccessControl(fileSec);
        }
开发者ID:jcde,项目名称:NAntWithContrib,代码行数:9,代码来源:AddAccessRuleTask.cs


注:本文中的System.Security.AccessControl.FileSystemAccessRule类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。