本文整理汇总了C#中System.Security.AccessControl.FileSecurity.SetAccessRule方法的典型用法代码示例。如果您正苦于以下问题:C# FileSecurity.SetAccessRule方法的具体用法?C# FileSecurity.SetAccessRule怎么用?C# FileSecurity.SetAccessRule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.AccessControl.FileSecurity
的用法示例。
在下文中一共展示了FileSecurity.SetAccessRule方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EnsureEveryoneHasPermissionsToWriteToLogFiles
/// <summary>
/// The install controller requires that the process is elevated (aka Run as Administrator).
/// The log files are created by this administrative account.
/// Any non-admin account will NOT have permissions to write to these log files.
/// By adding full control to "Everyone", the non-admin service can write to these logs.
/// </summary>
private void EnsureEveryoneHasPermissionsToWriteToLogFiles()
{
_installLog.Debug("Resetting permissions on all log files");
const string log4NetConfig = "log4net.config";
var assemblyPath = Assembly.GetExecutingAssembly().GetLocalPath();
var configPath = Path.Combine(assemblyPath, log4NetConfig);
var log4netConfig = File.ReadAllText(configPath);
var matches = Regex.Matches(log4netConfig, @"<param name=""File"" value=""(?<logPath>[^""]+)""\s*/>", RegexOptions.ExplicitCapture);
foreach (var logPath in matches.Cast<Match>().Select(m => m.Groups["logPath"].Value))
{
if (!File.Exists(logPath))
{
_installLog.WarnFormat("Attempting to reset permissions for log file but it is missing at '{0}'", logPath);
continue;
}
try
{
var fileSecurity = new FileSecurity(logPath, AccessControlSections.Access);
var everyoneSid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
fileSecurity.SetAccessRule(new FileSystemAccessRule(everyoneSid, FileSystemRights.FullControl, AccessControlType.Allow));
File.SetAccessControl(logPath, fileSecurity);
_installLog.DebugFormat("Reset permissions on '{0}'", logPath);
}
catch (Exception e)
{
_installLog.Error(string.Format("Failed to reset permissions on '{0}'", logPath), e);
}
}
}
示例2: CopyMiscellaneousFiles
private void CopyMiscellaneousFiles(IEnumerable<string> keys)
{
var fileSecurity = new FileSecurity();
fileSecurity.SetAccessRule(fileSystemAccessRule);
foreach (string key in keys.Where(x => x.EndsWith("_FILE")))
{
string path = Context.Parameters[key];
string destFileName = DestinationFilename(path);
File.Copy(path, destFileName, true);
File.SetAccessControl(destFileName, fileSecurity);
}
}
示例3: 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);
}
}
示例4: SetFileAccessControl
/// <summary>
/// Setzt volle Zugriffsrechte für eine Datei für den angemeldeten Benutzer.
/// </summary>
/// <param name="filename">Die Datei von welcher die Zugriffsrechte geändert werden sollen.</param>
/// <returns>Gibt 'True' zurück wenn die Zugriffsrechte erfolgreich gesetzt wurden, andernfalls 'False'.</returns>
protected bool SetFileAccessControl(string filename) {
try {
var fs = new FileSecurity();
var fs_rule = new FileSystemAccessRule(WindowsIdentity.GetCurrent().Name, FileSystemRights.FullControl,
AccessControlType.Allow);
fs.SetAccessRule(fs_rule);
File.SetAccessControl(filename, fs);
return true;
}
catch {
return false;
}
}