2017-07-18 24 views
1

我在Active Directory中四組:使用域組ACL C#

  • 只讀
  • 用戶
  • 經理
  • 合作伙伴

而且,我有一個Windows Server (2012)其中包含一些文件夾:

  • 管理
  • 公共
  • 限制
  • 規劃
  • Ressources

如何使用這些廣告組在此服務器上應用訪問規則,在我的C#應用​​程序?

回答

0

有辦法做到這一點!

AD組有這樣的特性:

group.properties["objectSID"]; 

我用它來:

SecurityIdentifier readOnlySID = new SecurityIdentifier(group.Properties["objectSID"][0] as byte[], 0); 

最後:

FileSystemAccessRule(readOnlySID, FileSystemRights.Read, AccessControlType Allow); 

這是管理ACL爲AD的唯一途徑小組!

0

我已經做在程序中插入您的數據,C#,並出口到Powershell的文件並運行它

enter image description here

這裏是寫權利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# enter image description here

+0

我想只使用C#:/ –

+0

@BaptisteMarcos對不起,沒有辦法做到這一點W/O PowerShell –

+0

@BaptisteMarcos你想看看這裏嗎?https://stackoverflow.com/questions/23780010 /共享-一個文件夾的許可,在-C-尖銳 –