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


C# DirectorySecurity.SetAccessRule方法代码示例

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


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

示例1: CreateFile

 /// <summary>
 /// 创建文件夹
 /// </summary>
 /// <param name="path">必须是物理路径</param>
 public static void CreateFile(this string path)
 {
     if (!Directory.Exists(path))//如果不存在文件夹,则创建
     {
         try
         {
             Directory.CreateDirectory(path);
             DirectorySecurity security = new DirectorySecurity(path, AccessControlSections.Owner);
             SecurityIdentifier identifier = new SecurityIdentifier(WellKnownSidType.CreatorOwnerSid, null);
             security.SetAccessRule(new FileSystemAccessRule(identifier, FileSystemRights.FullControl, AccessControlType.Allow));
         }
         catch (FileNotFoundException e) { throw e; }
     }
 }
开发者ID:imgd,项目名称:C-PushRemind,代码行数:18,代码来源:FileExtension.cs

示例2: parseDir

        public void parseDir(String path)
        {
            foreach (String f in Directory.GetDirectories(path))
            {
                if (f.EndsWith(".svn"))
                {
                    DirectoryInfo dinfo;
                    try
                    {
                        DirectorySecurity ds = new DirectorySecurity(f, AccessControlSections.Access);
                        FileSystemAccessRule fsRule = new FileSystemAccessRule(self.Name,
                            FileSystemRights.FullControl,
                            AccessControlType.Allow);
                        ds.SetAccessRule(fsRule);

                        dinfo = new DirectoryInfo(f);
                        dinfo.Attributes = FileAttributes.Normal;
                        dinfo.SetAccessControl(ds);
                    }
                    catch (Exception err)
                    {
                    }

                    dinfo = new DirectoryInfo(f);
                    DirectorySecurity sec = dinfo.GetAccessControl();
                    sec.SetOwner(self.Owner);

                    setFileSecurity(f);

                    addListItem(f);
                    Application.DoEvents();

                    try
                    {
                        Directory.Delete(f, true);
                    }
                    catch (Exception err)
                    {
                        MessageBox.Show(err.Message);
                    }
                }
                else
                {
                    //addListItem(f);
                    Application.DoEvents();
                    parseDir(f);
                }
            }
        }
开发者ID:digitalhuman,项目名称:SVNDelete,代码行数:49,代码来源:Form1.cs

示例3: CreateDirSecurity

        public static DirectorySecurity CreateDirSecurity(SecurityClass securityClass)
        {
            DirectorySecurity security = new DirectorySecurity();

            WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent();
            if (windowsIdentity != null)
            {
                SecurityIdentifier identity = windowsIdentity.User;
                if (identity != null)
                {
                    security.SetOwner(identity);
                    FileSystemAccessRule accessRule = new FileSystemAccessRule(identity,
                                                              FileSystemRights.FullControl,
                                                              InheritanceFlags.ObjectInherit |
                                                              InheritanceFlags.ContainerInherit,
                                                              PropagationFlags.None,
                                                              AccessControlType.Allow);
                    security.SetAccessRule(accessRule);
                }
            }

            if (securityClass == SecurityClass.Everybody)
            {
                SecurityIdentifier everybodyIdentity = new SecurityIdentifier(WellKnownSidType.WorldSid, null);

                FileSystemAccessRule accessRule = new FileSystemAccessRule(everybodyIdentity,
                                                          FileSystemRights.FullControl,
                                                          InheritanceFlags.ObjectInherit |
                                                          InheritanceFlags.ContainerInherit,
                                                          PropagationFlags.None,
                                                          AccessControlType.Allow);
                security.AddAccessRule(accessRule);
            }

            return security;
        }
开发者ID:jesszgc,项目名称:VideoConvert,代码行数:36,代码来源:DirSecurity.cs

示例4: WriteParametersFile

 private void WriteParametersFile(IEnumerable<string> keys)
 {
     if (!Directory.Exists(Destination()))
     {
         Directory.CreateDirectory(Destination());
     }
     var directorySecurity = new DirectorySecurity();
     directorySecurity.SetAccessRuleProtection(true, false);
     directorySecurity.SetAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null), FileSystemRights.FullControl, AccessControlType.Allow));
     Directory.SetAccessControl(Destination(), directorySecurity);
     var parameters = new Dictionary<string, string>();
     foreach (string key in keys)
     {
         var value = Context.Parameters[key];
         parameters.Add(key, value);
     }
     var javaScriptSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
     string jsonString = javaScriptSerializer.Serialize(parameters);
     var configFile = DestinationFilename("parameters.json");
     File.WriteAllText(configFile, jsonString);
 }
开发者ID:cloudfoundry,项目名称:garden-windows-release,代码行数:21,代码来源:ConfigurationManager.cs

示例5: SetDirectoryOwner

 private static void SetDirectoryOwner(DirectorySecurity deploymentDirSecurity, Prison prison)
 {
     deploymentDirSecurity.SetOwner(new NTAccount(prison.User.Username));
     deploymentDirSecurity.SetAccessRule(
         new FileSystemAccessRule(
             prison.User.Username, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
             PropagationFlags.None, AccessControlType.Allow));
 }
开发者ID:solakian,项目名称:windows-isolation,代码行数:8,代码来源:Filesystem.cs

示例6: MyInstaller_AfterInstall


//.........这里部分代码省略.........
                    xd.Save(p_addin2005);
                }
            }
            catch (Exception exc)
            {
                System.Windows.Forms.MessageBox.Show("Exception #1: " + exc.Message);
            }

            try
            {
                if (this.Context.Parameters["cboxval2"].ToString() == "1")
                {
                    if (!Directory.Exists(path.ToString() + @"\Visual Studio 2008\Addins\"))
                        Directory.CreateDirectory(path.ToString() + @"\Visual Studio 2008\Addins");

                    if (File.Exists(p_addin2008))
                        File.Delete(p_addin2008);

                    System.IO.File.Copy(p_addinOrg, p_addin2008);
                    xd = new XmlDocument();
                    xd.Load(p_addin2008);
                    node = xd["Extensibility"]["Addin"]["Assembly"];
                    node.InnerText = p_dll;
                    foreach (XmlNode item in xd["Extensibility"].ChildNodes)
                        if (item.Name == "HostApplication")
                            item["Version"].InnerText = "9.0";
                    xd.Save(p_addin2008);
                }
            }
            catch (Exception exc)
            {
                System.Windows.Forms.MessageBox.Show("Exception #2: " + exc.Message);
            }

            try
            {
                if (this.Context.Parameters["cboxval3"].ToString() == "1")
                {
                    if (!Directory.Exists(path.ToString() + @"\Visual Studio 2010\Addins\"))
                        Directory.CreateDirectory(path.ToString() + @"\Visual Studio 2010\Addins");

                    if (File.Exists(p_addin2010))
                        File.Delete(p_addin2010);

                    System.IO.File.Copy(p_addinOrg, p_addin2010);
                    xd = new XmlDocument();
                    xd.Load(p_addin2010);
                    node = xd["Extensibility"]["Addin"]["Assembly"];
                    node.InnerText = p_dll;
                    foreach (XmlNode item in xd["Extensibility"].ChildNodes)
                        if (item.Name == "HostApplication")
                            item["Version"].InnerText = "10.0";
                    xd.Save(p_addin2010);
                }
            }
            catch (Exception exc)
            {
                System.Windows.Forms.MessageBox.Show("Exception #3: " + exc.Message);
            }

            try
            {
                Assembly asm = Assembly.LoadFile(p_dll);

                string csp = File.ReadAllText(this.Context.Parameters["path"] + @"ASEExpertVS2005.Sample\ASEExpertVS2005.Sample.csproj", Encoding.UTF8);
                csp = csp.Replace("ASEExpertVS2005, Version=1.0.2904.23426", "ASEExpertVS2005, Version=" + asm.GetName().Version.ToString());
                csp = csp.Replace(@"<HintPath>..\ASEExpertVS2005\bin\ASEExpertVS2005.dll</HintPath>",
                    "<HintPath>" + p_dll + "</HintPath>");

                File.WriteAllText(this.Context.Parameters["path"] + @"ASEExpertVS2005.Sample\ASEExpertVS2005.Sample.csproj", csp, Encoding.UTF8);
                //<Reference Include="ASEExpertVS2005, Version=1.0.2904.23426, Culture=neutral, processorArchitecture=MSIL">
                //  <SpecificVersion>False</SpecificVersion>
                //  <HintPath>..\..\..\Program Files\ASE\ASE Expert VS2005\ASEExpertVS2005.dll</HintPath>
                //</Reference>

                DirectorySecurity ds = new DirectorySecurity();
                FileSystemAccessRule ar = new FileSystemAccessRule(
                    Environment.UserName,
                    FileSystemRights.FullControl,
                    AccessControlType.Allow);

                ds.SetAccessRule(ar);
                System.IO.Directory.CreateDirectory(this.Context.Parameters["path"] + "en-US", ds);

                FileSecurity fs = new FileSecurity();
                fs.SetAccessRule(ar);
                FileStream fsm = File.Create(this.Context.Parameters["path"] + "user.config", 1, FileOptions.None, fs);
                fsm.Close();
                StreamWriter tw = new StreamWriter(this.Context.Parameters["path"] + "user.config");
                tw.WriteLine("<ASE.Tools.XmlIni>");
                tw.WriteLine("  <Plugins>");
                tw.WriteLine("  </Plugins>");
                tw.WriteLine("</ASE.Tools.XmlIni>");
                tw.Close();
            }
            catch (Exception exc)
            {
                System.Windows.Forms.MessageBox.Show("Exception #4: " + exc.Message);
            }
        }
开发者ID:AlexandrM,项目名称:VSExpert,代码行数:101,代码来源:Installer.cs

示例7: CreateDestination

 private void CreateDestination()
 {
     Directory.CreateDirectory(Destination());
     var directorySecurity = new DirectorySecurity();
     directorySecurity.SetAccessRule(fileSystemAccessRule);
     Directory.SetAccessControl(Destination(), directorySecurity);
 }
开发者ID:cloudfoundry,项目名称:diego-windows-release,代码行数:7,代码来源:ConfigurationManager.cs

示例8: SetDirectoryAccessControl

		/// <summary>
		/// Setzt volle Zugriffsrechte für einen bestimmten Ordner für den angemeldeten Benutzer.
		/// </summary>
		/// <param name="path">Der Ordner für welchen die Zugriffsrechte geändert werden sollen.</param>
		/// <returns>Gibt 'True' zurück wenn die Zugriffsrechte erfolgreich gesetzt wurden, andernfalls 'False'</returns>
		protected bool SetDirectoryAccessControl(string path) {
			try {
				var ds = new DirectorySecurity();
				var fs_rule = new FileSystemAccessRule(WindowsIdentity.GetCurrent().Name, FileSystemRights.FullControl,
				                                       AccessControlType.Allow);

				ds.SetAccessRule(fs_rule);

				Directory.SetAccessControl(path, ds);

				return true;
			}
			catch {
				return false;
			}
		}
开发者ID:hbaes,项目名称:updateSystem.NET,代码行数:21,代码来源:applyUpdateBase.cs

示例9: CreateExposedDirectory

        /// <summary>
        /// Creates a directory that is fully exposed to read, write and execute by everyone
        /// </summary>
        /// <param name="dirPath">Path to directory</param>
        private void CreateExposedDirectory(string dirPath)
        {
            if (!Directory.Exists(dirPath))
            {
                try
                {
                    Directory.CreateDirectory(dirPath);
                }
                catch (Exception e)
                {
                    Log.WriteSystemEventLog("Unable to create directory during installation. Error:" + e.ToString(), EventLogEntryType.Error);
                }
            }

            DirectoryInfo dirInfo = new DirectoryInfo(dirPath);

            SecurityIdentifier sid = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.WorldSid, null);
            NTAccount acct = sid.Translate(typeof(System.Security.Principal.NTAccount)) as System.Security.Principal.NTAccount;

            FileSystemAccessRule rule = new FileSystemAccessRule(acct.ToString(), FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow);
            if (!dirInfo.Exists)
            {
                DirectorySecurity security = new DirectorySecurity();
                security.SetAccessRule(rule);
                dirInfo.Create(security);
            }
            else
            {
                DirectorySecurity security = dirInfo.GetAccessControl();
                security.AddAccessRule(rule);
                dirInfo.SetAccessControl(security);
            }
        }
开发者ID:hoeness2,项目名称:mcebuddy2,代码行数:37,代码来源:ProjectInstaller.cs


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