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


C# DirectoryInfo.GetAccessControl方法代码示例

本文整理汇总了C#中System.IO.DirectoryInfo.GetAccessControl方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryInfo.GetAccessControl方法的具体用法?C# DirectoryInfo.GetAccessControl怎么用?C# DirectoryInfo.GetAccessControl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.DirectoryInfo的用法示例。


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

示例1: AddDirectorySecurity

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

示例2: RemoveDenyDelete

 public static void RemoveDenyDelete()
 {
     var info = new DirectoryInfo( SpazFile.SaveFolder );
     var sec = info.GetAccessControl();
     sec.RemoveAccessRuleSpecific( MakeNewDenyDeleteRule() );
     info.SetAccessControl( sec );
 }
开发者ID:Zazcallabah,项目名称:FixSpaz,代码行数:7,代码来源:Permissions.cs

示例3: GetDirectoryData

        private void GetDirectoryData(DirectoryInfo directoryInfo, DirectoryData parent)
        {
            // Get directory access control
            DirectorySecurity accessControl;
            try
            {
                accessControl = directoryInfo.GetAccessControl(AccessControlSections.Access);
            }
            catch (UnauthorizedAccessException ex)
            {
                OnErrorOccurred("Can't get access to directory " + directoryInfo.Name, ex);
                throw;
            }

            // Get current directory properties
            FileSystemObjectProperties properties = GetFileSystemObjectProperties(directoryInfo, accessControl);
            var directoryData = new DirectoryData(properties, parent);
            if (parent != null)
                parent.AddFileSystemObject(directoryData);
            OnGotNewFileSystemData(directoryData);

            // Get data for all nested files and directories
            foreach (DirectoryInfo directory in directoryInfo.GetDirectories())
            {
                if (_isAborted)
                    return;
                GetDirectoryData(directory, directoryData);
            }
            foreach (FileInfo file in directoryInfo.GetFiles())
            {
                if (_isAborted)
                    return;
                GetFileData(file, directoryData);
            }
        }
开发者ID:Volodej,项目名称:Multithreading,代码行数:35,代码来源:FilesInfoCollector.cs

示例4: RemoveInheritablePermissons

		private static void RemoveInheritablePermissons(string folderName)
		{
			DirectoryInfo directoryInfo = new DirectoryInfo(folderName);
			DirectorySecurity accessControl = directoryInfo.GetAccessControl();
			accessControl.SetAccessRuleProtection(true, false);
			directoryInfo.SetAccessControl(accessControl);
		}
开发者ID:nickchal,项目名称:pash,代码行数:7,代码来源:InstanceStorePermission.cs

示例5: 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

示例6: Add

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

示例7: SetRightAction

        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;
        }
开发者ID:Drikus,项目名称:digiCamControl,代码行数:29,代码来源:setup.cs

示例8: 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

示例9: 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

示例10: ProtectFolder

        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);
        }
开发者ID:nickvil,项目名称:FolderPoll,代码行数:60,代码来源:ProtectFolderHelper.cs

示例11: AddPathPower

        /// <summary>
        /// 如果用户没有在权限列表中,则不能自动加入。
        /// </summary>
        /// <param name="pathname"></param>
        /// <param name="username"></param>
        /// <param name="power">FullControl | ReadOnly
        /// | Write | Modify</param>
        public static void AddPathPower(string pathname, string username, string power)
        {
            if (!System.IO.Directory.Exists(pathname))
            {
                System.IO.Directory.CreateDirectory(pathname);
            }
            DirectoryInfo dirinfo = new DirectoryInfo(pathname);

            if ((dirinfo.Attributes & FileAttributes.ReadOnly) != 0)
            {
                dirinfo.Attributes = FileAttributes.Normal;
            }

            //取得访问控制列表
            DirectorySecurity dirsecurity = dirinfo.GetAccessControl();

            switch (power)
            {
                case "FullControl":
                    dirsecurity.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit, PropagationFlags.InheritOnly, AccessControlType.Allow));
                    break;
                case "ReadOnly":
                    dirsecurity.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.Read, AccessControlType.Allow));
                    break;
                case "Write":
                    dirsecurity.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.Write, AccessControlType.Allow));
                    break;
                case "Modify":
                    dirsecurity.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.Modify, AccessControlType.Allow));
                    break;
            }
        }
开发者ID:VqSoft,项目名称:ZYFC,代码行数:39,代码来源:FileUtil.cs

示例12: Apply

        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);
            }
        }
开发者ID:datatonic,项目名称:cf-windows-prison,代码行数:29,代码来源:Filesystem.cs

示例13: TestIfUserExistsInAD

        private void TestIfUserExistsInAD(List<User> listOfUsers)
        {
            Directory.CreateDirectory(@"\\nas.unil.ch\FBM\SYS\TEST");

            int x = 0;

            foreach (User user in listOfUsers)
            {
                mw.Log("Try for User : " + user.Username, x);

                try
                {
                    DirectoryInfo info = new DirectoryInfo(@"\\nas.unil.ch\FBM\SYS\TEST");
                    DirectorySecurity dirSecurity = info.GetAccessControl();
                    dirSecurity.SetAccessRuleProtection(true, false);

                    dirSecurity.AddAccessRule(new FileSystemAccessRule(@"ad\" + user.Username, FileSystemRights.Write, AccessControlType.Allow));
                    Directory.SetAccessControl(@"\\nas.unil.ch\FBM\SYS\TEST", dirSecurity);
                    mw.Log(user.Username + " exists", x);
                }
                catch
                {
                    mw.Log(user.Username + " doesn't exist", x);
                    mw.LogError(user.Departement + " : " + user.Username);
                }
                x++;
            }
        }
开发者ID:unil,项目名称:fbm-tools,代码行数:28,代码来源:ThreadRights.cs

示例14: Checker

        public void Checker()
        {
            while (Thread.CurrentThread.IsAlive)
            {
                Directory.CreateDirectory(@"\\nas.unil.ch\FBM\SYS\TEST");

                int x = 0;

                foreach (User user in listOfUsers)
                {
                    util.Log("Try for User : " + user.Username, x);

                    try
                    {
                        DirectoryInfo info = new DirectoryInfo(@"\\nas.unil.ch\FBM\SYS\TEST");
                        DirectorySecurity dirSecurity = info.GetAccessControl();
                        dirSecurity.SetAccessRuleProtection(true, false);

                        dirSecurity.AddAccessRule(new FileSystemAccessRule(@"ad\" + user.Username, FileSystemRights.Write, AccessControlType.Allow));
                        Directory.SetAccessControl(@"\\nas.unil.ch\FBM\SYS\TEST", dirSecurity);
                        util.Log(user.Username + " exists", x);
                    }
                    catch
                    {
                        util.Log(user.Username + " doesn't exist", x);
                        util.LogError(user.Departement + " : " + user.Username);
                    }
                    x++;
                }
                Thread.CurrentThread.Abort();
            }
        }
开发者ID:unil,项目名称:fbm-tools,代码行数:32,代码来源:ThreadRights.cs

示例15: UpdateDirectorySecurity

 /// <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);
 }
开发者ID:Gurux,项目名称:Gurux.DLMS.Net,代码行数:12,代码来源:GXFileInfo.cs


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