简体   繁体   中英

C# get obscure Active Directory Attributes

I'm trying to retrieve some obsure Active Directory Attributes:

  1. msexchmailboxsecuritydescriptor, and
  2. terminalservicesprofilepath (in userparameters)

I am having trouble getting to both of them.

For example, for msexchmailboxsecuritydescriptor, if I have code similar to the following:

DirectoryEntry deresult = result.GetDirectoryEntry();
byte[] bteMailACL =(byte[])deresult.Properties["msexchmailboxsecuritydescriptor"].Value; 

It complains that I cannot cast System.__ComObject to System.Byte[], but I have seen several example that use code similar to the above.

How do I understand these blobs of information?

I think your problem is in .Value part of the statement. Not sure how the examples have been doing it but I've noticed that whenever I call an AD Property like that, I always get an array back of which I get index 0 in case of single result items.

just changing the last statment to:

    byte[] btwMailACL = (byte[])deresult.Properties["msexchmailboxsecuritydescriptor"][0];

solves your problem.

Edit: for production code, please do remember that this can throw a NullReferenceException so do check if the property actually returned a value before calling on the index.

(Tested on my machine and working as above)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM