C#: Returning ADSI COM Properties of a User Object (Or Any Object, Really)


A few months ago, I was working on a project to query for specific AD properties of a user-object programmatically. I knew the properties I wanted to return and I had worked with returning properties in ExBPA/HRC. I hadn't, however, found the joys of receiving a System.__COM object in any of my returns until now.

To explain this, you should familiarize yourself with ADSI (Active Directory Service Interfaces), if you've never been exposed to it, before. As the previous link points out, ADSI is a COM (Component Object Model), and - as such - we will get a return of 'System.__COM', if we fail to pull the data in the expected format.

So, how was I to return the data from the COM? Well, as it turns out, there's 'deprecated' documentation which helped me farther than any blog, technical bulletin, or reference did. You can find it, here. (Apologies, apparently all of the English versions have been pulled because it was deprecated.)

Using some ingenuity and a little luck, I found the answer to my problem: return the value I'm querying for as 'ActiveDs.IADsLargeInteger'.

So, armed with this knowledge, I could now pull the properties I wanted to return in usable context, like the following:

ActiveDs.IADsLargeInteger recipientTypeDetails = (ActiveDs.IADsLargeInteger)userResult.Properties["msExchRecipientTypeDetails"].Value as ActiveDs.IADsLargeInteger;

Once I had the data 'out', as it were, I could try to manipulate it:

long recipTypeDetails = recipientTypeDetails.LowPart;

I realize this doesn't mean much to some people (maybe a lot) but I figured if I could save one person the hours it took me to find the answer, then it was well worth the time in writing this.

Happy coding!

Comments (4)

  1. Rattana says:

    Thank you so much for this blog. I had been pulling my hair out trying to figured it out.

  2. vindy says:

    you definitely saved my half of the day.Thanks

  3. pregunton says:

    Why use ActiveDs.IADsLargeInteger ? not possible only using System.DirectoryServices.AccountManagement ?

  4. Mike M says:

    Thanks a bunch! I burned half the morning following dead-end results, until I found your post. Within 5 minutes I located the ENGLISH version of the ADSI reference link, and had pushed through the wall of coaxing out the values I needed.

    By the way, I found the article at https://msdn.microsoft.com/en-us/library/ms180868(v=vs.80).aspx by searching the MSDN site for MS180868 and the en-us link popped up.

Skip to main content