Mat*_*ord 16 c# security permissions ntfs
我有一个问题,我需要为所有经过身份验证的用户添加对文件夹的访问权限,以存储与应用程序相关的设置.我发现这可以通过以下代码完成...
var Info = new DirectoryInfo(settingsdir);
var Security = Info.GetAccessControl(AccessControlSections.Access);
Security.AddAccessRule(
new FileSystemAccessRule(
"Authenticated Users", FileSystemRights.Modify,
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
PropagationFlags.None,
AccessControlType.Allow));
Run Code Online (Sandbox Code Playgroud)
我发现的问题是"Authenticated Users"是Windows上的系统帐户,但是在Windows的不同语言版本上,此帐户名被翻译,例如在德国,该帐户被称为"Authentifizierte Benutzer".有没有办法知道这个帐户的正确名称(显而易见的是通过每种语言并找到正确的帐户名称).
Grh*_*rhm 28
我建议你使用Well Known SID列表(参见http://support.microsoft.com/kb/243330).经过身份验证的用户始终为SID:S-1-5-11.如果你使用它,它应该是语言不可知的(但我没有测试过).
创建一个SecurityIdentifier并使用它:
var sid = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null);
Security.AddAccessRule(
new FileSystemAccessRule(
sid,
FileSystemRights.Modify,
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
PropagationFlags.None,
AccessControlType.Allow));
Run Code Online (Sandbox Code Playgroud)