开发者

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 the开发者_如何学JAVAm.

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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜