为 ACL C# 使用域组
Use domain group for ACL C#
我的活动目录中有四个组:
- 只读
- 用户
- 经理
- 合作伙伴
而且,我有一个 Windows 服务器 (2012),其中包含一些文件夹:
- 管理
- Public
- 受限
- 规划中
- 资源
如何在我的 C# 应用程序中使用这些 AD 组在此服务器上应用访问规则?
我已经制作了程序 Insert your data to C# and export to Powershell file and 运行 it
这里是写权限的powershell代码
$acl = Get-Acl "\Server\Testshare"
$acl.SetAccessRuleProtection($False,$false)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule('Server_Testshare_local','modify','ContainerInherit,ObjectInherit','None','Allow')
$acl.AddAccessRule($rule)
Set-Acl "\Server\Testshare" $acl
以及阅读权限
$acl = Get-Acl "\Server\Testshare"
$acl.SetAccessRuleProtection($False,$false)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule('Server_Testshare_Read local','ReadAndExecute','ContainerInherit,ObjectInherit','None','Allow')
$acl.AddAccessRule($rule)
Set-Acl "\Server\Testshare" $acl
和 C#
有办法做到!
AD 组具有以下属性:
group.properties["objectSID"];
我用它来:
SecurityIdentifier readOnlySID = new SecurityIdentifier(group.Properties["objectSID"][0] as byte[], 0);
最后:
FileSystemAccessRule(readOnlySID, FileSystemRights.Read, AccessControlType Allow);
这是管理 AD 组的 ACL 的唯一方法!
我的活动目录中有四个组:
- 只读
- 用户
- 经理
- 合作伙伴
而且,我有一个 Windows 服务器 (2012),其中包含一些文件夹:
- 管理
- Public
- 受限
- 规划中
- 资源
如何在我的 C# 应用程序中使用这些 AD 组在此服务器上应用访问规则?
我已经制作了程序 Insert your data to C# and export to Powershell file and 运行 it
这里是写权限的powershell代码
$acl = Get-Acl "\Server\Testshare"
$acl.SetAccessRuleProtection($False,$false)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule('Server_Testshare_local','modify','ContainerInherit,ObjectInherit','None','Allow')
$acl.AddAccessRule($rule)
Set-Acl "\Server\Testshare" $acl
以及阅读权限
$acl = Get-Acl "\Server\Testshare"
$acl.SetAccessRuleProtection($False,$false)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule('Server_Testshare_Read local','ReadAndExecute','ContainerInherit,ObjectInherit','None','Allow')
$acl.AddAccessRule($rule)
Set-Acl "\Server\Testshare" $acl
和 C#
有办法做到!
AD 组具有以下属性:
group.properties["objectSID"];
我用它来:
SecurityIdentifier readOnlySID = new SecurityIdentifier(group.Properties["objectSID"][0] as byte[], 0);
最后:
FileSystemAccessRule(readOnlySID, FileSystemRights.Read, AccessControlType Allow);
这是管理 AD 组的 ACL 的唯一方法!