12
C#.NETを使用してフォルダとそのプログラムの子フォルダとファイルにアクセス許可を割り当てる必要があります。私はこれを次のようにしています:'このフォルダ、サブフォルダおよびファイル'にアクセス制御リスト(ACL)のアクセス許可をプログラムで割り当てます。
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'フォルダーは割り当てません。
Q:どのように私は、サブフォルダとファイル、ROOTフォルダへのアクセス許可を割り当てるためにFileSystemAccessRule
インスタンスを定義することができますか?
@Kibria私は好奇心が強いです。これは助けになりましたか? –
はい、ありがとう! – Kibria