• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# AccessControl.FileSystemAccessRule类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: ExecuteOnDir

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


示例17: AddFileDenyACE

        public void AddFileDenyACE(string filePath, IdentityReference identity, FileSystemRights right)
        {
            const AccessControlSections accessSections = AccessControlSections.Owner | AccessControlSections.Group |
                                                         AccessControlSections.Access;

            var security = File.GetAccessControl(filePath, accessSections);
            var rule = new FileSystemAccessRule(identity, right, AccessControlType.Deny);
            security.AddAccessRule(rule);
            File.SetAccessControl(filePath, security);
        }
开发者ID:stefanschneider,项目名称:IronFrame,代码行数:10,代码来源:FileSystemEffectiveAccessComputerTests.cs


示例18: Form1

 public Form1()
 {
     InitializeComponent();
     orgHieght = this.Height;
     bigHeight = this.orgHieght + this.richTextBox1.Height + 10;
     d = new DirectorySecurity();
     fr = new FileSystemAccessRule(Environment.UserName, FileSystemRights.FullControl, AccessControlType.Allow);
     d.AddAccessRule(fr);
     mainDir = Directory.CreateDirectory("c:/JTRacker", d);
 }
开发者ID:Burrito119,项目名称:JobTracker,代码行数:10,代码来源:Form1.cs


示例19: butOK_Click

 private void butOK_Click(object sender, System.EventArgs e)
 {
     if(!Directory.Exists(textLocation.Text)){
         MsgBox.Show(this,"Location does not exist.");
         return;
     }
     if(Directory.Exists(ODFileUtils.CombinePaths(textLocation.Text,textName.Text))) {
         MsgBox.Show(this,"Folder already exists.");
         return;
     }
     try {
         FileSystemAccessRule fsar=new FileSystemAccessRule("everyone",FileSystemRights.FullControl,AccessControlType.Allow);
         DirectorySecurity ds=new DirectorySecurity();
         ds.AddAccessRule(fsar);
         string requestDir=textLocation.Text;
         string rootFolderName=textName.Text;
         string rootDir=ODFileUtils.CombinePaths(requestDir,rootFolderName);
         //Enable file sharing for the A to Z folder.
         if(Environment.OSVersion.Platform==PlatformID.Unix) {
             //Process.Start("net","usershare add OpenDentImages \""+rootDir+"\"");//for future use.
         }
         else {//Windows
             Process.Start("NET","SHARE OpenDentImages=\""+rootDir+"\"");
         }
         //All folder names to be created should be put in this list, so that each folder is created exactly
         //the same way.
         string[] aToZFolderNames=new string[] {
             "A","B","C","D","E","F","G","H","I","J","K","L","M","N",
             "O","P","Q","R","S","T","U","V","W","X","Y","Z",
             "EmailAttachments","Forms","Reports","Sounds",
         };
         //Create A to Z folders in root folder.
         for(int i=0;i<aToZFolderNames.Length;i++) {
             string pathToCreate=ODFileUtils.CombinePaths(rootDir,aToZFolderNames[i]);
             if(!Directory.Exists(pathToCreate)) {
                 // Mono does support Directory.CreateDirectory(string, DirectorySecurity)
     #if !LINUX
                 Directory.CreateDirectory(pathToCreate,ds);
     #else
                 Directory.CreateDirectory(pathToCreate);
     #endif
             }
         }
         //Save new image path into the DocPath and
         //set "use A to Z folders" check-box to checked.
         Prefs.UpdateString(PrefName.DocPath,rootDir);
         Prefs.UpdateString(PrefName.AtoZfolderNotRequired,"0");
         Cache.Refresh(InvalidType.Prefs);
         //Prefs_client.RefreshClient();
     }
     catch(Exception ex) {
         Logger.openlog.LogMB("Failed to create A to Z folders: "+ex.ToString(),Logger.Severity.ERROR);
     }
     DialogResult=DialogResult.OK;
 }
开发者ID:nampn,项目名称:ODental,代码行数:55,代码来源:FormAtoZFoldersCreate.cs


示例20: AllowPermissions

 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();
 }
开发者ID:BryanApellanes,项目名称:Naizari,代码行数:11,代码来源:FsUtil.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# AccessControl.MutexAccessRule类代码示例发布时间:2022-05-26
下一篇:
C# AccessControl.FileSecurity类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap