Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting 'System.__ComObject' from my LDAP property?

I'll be the first to admit that this is cut and past programming. I've never looked at AD before, and really don't understand it. I suppose that's my next study...

Anyways, This is some test code, which should display the expiry date -- either as something readable, or in ticks -- it doesn't matter. (It's a web form, which is running on the dev webserver.)

What I get instead is: "System.__ComObject "

DirectorySearcher searcher = new DirectorySearcher();
searcher.Filter = String.Format( "(SAMAccountName={0})", "TestA33" );
searcher.PropertiesToLoad.Add( "cn" );

SearchResult result = searcher.FindOne();
DirectoryEntry uEntry = result.GetDirectoryEntry();

String expiry = uEntry.Properties["accountExpires"].Value.ToString(); 

Response.Write( expiry );
like image 326
Chris Cudmore Avatar asked Dec 30 '22 06:12

Chris Cudmore


2 Answers

The article that Dave Cluderay recommended is a good idea. One important thing to note is that if expiration is set to never, the date you get might not make sense.

According to MS documentation, the IADsLargeInteger from the ADSI call represents the number of 100 nanosecond intervals since Jan 1, 1601 (UTC) and "value of 0 or 0x7FFFFFFFFFFFFFFF (9223372036854775807) indicates that the account never expires".

like image 119
barneytron Avatar answered Jan 14 '23 13:01

barneytron


It's because the property value is represented using the ADSI IADsLargeInteger COM interface and needs to be converted to a .NET date. Although I haven't tried it, there is a sample that shows how here: http://www.simple-talk.com/dotnet/.net-framework/building-active-directory-wrappers-in-.net/

like image 23
Dave Cluderay Avatar answered Jan 14 '23 14:01

Dave Cluderay