フォルダーにアクセス許可を割り当てる必要があり、それは C#.NET を使用してプログラムで子フォルダーとファイルです。私は以下のようにこれをやっています:
var rootDic = @"C:\ROOT";
var identity = "NETWORK SERVICE"; //The name of a user account.
try
{
var accessRule = new FileSystemAccessRule(identity,
fileSystemRights: FileSystemRights.Modify,
inheritanceFlags: InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
propagationFlags: PropagationFlags.InheritOnly,
type: AccessControlType.Allow);
var directoryInfo = new DirectoryInfo(rootDic);
// Get a DirectorySecurity object that represents the current security settings.
DirectorySecurity dSecurity = directoryInfo.GetAccessControl();
// Add the FileSystemAccessRule to the security settings.
dSecurity.AddAccessRule(accessRule);
// Set the new access settings.
directoryInfo.SetAccessControl(dSecurity);
}
catch (Exception ex)
{
//...
}
「C:\ROOT」フォルダーにアクセス許可を割り当てます。ただし、サブフォルダーとファイルのみにアクセス許可を割り当てますが、「ROOT」フォルダーには割り当てません。
FileSystemAccessRule
Q:インスタンスを定義して、ROOT フォルダー、サブフォルダー、およびファイルにアクセス許可を割り当てるにはどうすればよいですか?