本文整理汇总了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; }
}
}
示例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);
}
}
}
示例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;
}
示例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);
}
示例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));
}
示例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);
}
}
示例7: CreateDestination
private void CreateDestination()
{
Directory.CreateDirectory(Destination());
var directorySecurity = new DirectorySecurity();
directorySecurity.SetAccessRule(fileSystemAccessRule);
Directory.SetAccessControl(Destination(), directorySecurity);
}
示例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;
}
}
示例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);
}
}