I'm trying to add a group to a mailbox (in C#). I'm using a mix of CDOEXM, DirectoryServices.AccountManagement calls, and failing. 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.
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). The variable userDe is a 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();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.