[英]Setting ACL on Exchange Mailbox
I'm trying to add a group to a mailbox (in C#). 我正在尝试将组添加到邮箱(在C#中)。 I'm using a mix of CDOEXM, DirectoryServices.AccountManagement calls, and failing. 我混合使用了CDOEXM,DirectoryServices.AccountManagement和失败。 This is my code: 这是我的代码:
// userDe is a DirectoryEntry
IExchangeMailbox exMb = (IExchangeMailbox)userDe.NativeObject;
IADsSecurityDescriptor securityDescriptor = (IADsSecurityDescriptor)exMb.MailboxRights;
IADsAccessControlList acl = (IADsAccessControlList)securityDescriptor.DiscretionaryAcl;
AccessControlEntry ace = new AccessControlEntry();
// groupName - I have successfully created the group earlier
ace.Trustee = groupName;
acl.AddAce(ace);
securityDescriptor.DiscretionaryAcl = acl;
exMb.MailboxRights = securityDescriptor;
// How do I save it?
exMb.CommitChanges() etc etc
...or userDe.Properties["ntSecurityDescriptor"] = securityDescriptor;
Not sure what to do next, everything I try results in a compilation error or a InvalidCastException. 不知道下一步该怎么做,我尝试的所有操作都会导致编译错误或InvalidCastException。
Please help 请帮忙
Got it after quite a bit of pain (the integer values I am setting somehow correspond to enum values in the API but I couldn't get them to work). 经过一番痛苦之后得到了它(我以某种方式设置的整数值对应于API中的枚举值,但我无法使它们起作用)。 The variable userDe is a DirectoryEntry. 变量userDe是DirectoryEntry。
IExchangeMailbox exMb = (IExchangeMailbox)userDe.NativeObject;
IADsSecurityDescriptor securityDescriptor = (IADsSecurityDescriptor)exMb.MailboxRights;
IADsAccessControlList acl = (IADsAccessControlList)securityDescriptor.DiscretionaryAcl;
AccessControlEntry ace = new AccessControlEntry();
ace.Trustee = groupName;
ace.AccessMask = 1;
ace.AceFlags = 2;
ace.AceType = 0;
acl.AddAce(ace);
securityDescriptor.DiscretionaryAcl = acl;
IADsUser iadsUser = (IADsUser)userDe.NativeObject;
iadsUser.Put("msExchMailboxSecurityDescriptor", securityDescriptor);
iadsUser.SetInfo();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.