我正在尝试将一个组添加到邮箱(在C#中)。我正在使用CDOEXM,DirectoryServices.AccountManagement调用和失败的混合。这是我的代码:
// 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;
不确定下一步该做什么,我尝试的所有内容都会导致编译错误或InvalidCastException。
请帮忙
答案 0 :(得分:0)
经过相当多的痛苦后得到它(我设置的整数值以某种方式对应于API中的枚举值,但我无法让它们工作)。变量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();