这是我的代码,我尝试了相同的文件访问控制代码,它运行良好。 但不适用于Vista上的常见应用程序数据。
private static void GrantEveryoneFullControlRight(string directory)
{
try
{
if (!Directory.Exists(directory))
Directory.CreateDirectory(directory);
DirectoryInfo dirInfo = new DirectoryInfo(directory);
DirectorySecurity ds = dirInfo.GetAccessControl(AccessControlSections.Access);
FileSystemAccessRule rule = new FileSystemAccessRule(
"Users", FileSystemRights.FullControl, AccessControlType.Allow);
ds.AddAccessRule(rule);
dirInfo.SetAccessControl(ds);
}
catch (Exception ex)
{
// Logger.WriteLog(LogType.Error, ex.ToString());
Console.WriteLine(ex.ToString());
}
}