AccountExpires WITHOUT ACTIVEDS

G

Guest

In c#,

How can I get the "accountExpires" without having to register the ACTIVEDS
COM object on the client?

DirectoryEntry returns almost all value with the COM object except for dates.

Why MS designed .NET object returning COM object? I hoped we got rid of the
complexity of COM in .NET

Now it seems I have to make install program for .NET program to installed
COM DLL only because .NET object are returning COM object.
 
W

Willy Denoyette [MVP]

| In c#,
|
| How can I get the "accountExpires" without having to register the ACTIVEDS
| COM object on the client?
|
You don't have to register activeds on the client, activeds is part of the
system install.

| DirectoryEntry returns almost all value with the COM object except for
dates.
|
| Why MS designed .NET object returning COM object? I hoped we got rid of
the
| complexity of COM in .NET
|
Because the functionality was there and stable?

| Now it seems I have to make install program for .NET program to installed
| COM DLL only because .NET object are returning COM object.


Again, you don't have to install anything COM, activeds.tlb and activeds.dll
are already installed.


You can "late bind" to the underlying activeds.dll by using reflection, or
if that's also too complicated, you can use vb.net which supports this
out-of-the-box.
But I guess you are talking about the interop assembly, you can get rid of
it by using reflection to invoke members on the COM interface, or you can
use vb.net which supports late binding at the language level.

// say user is a DirectoryEntry representing a AD user object.
long expDate =
LongFromLargeInteger(user.Properties["accountExpires"].Value);
//Now, convert the long returned to dateTime, but beware that -1 is returned
for "account never expires", which is an invalid data!
....

private static long LongFromLargeInteger( object largeInteger )
{
System.Type type = largeInteger.GetType();
int highPart =
(int)type.InvokeMember("HighPart",BindingFlags.GetProperty,
null, largeInteger, null);
int lowPart = (int)type.InvokeMember("LowPart",BindingFlags.GetProperty,
null, largeInteger, null);
return (long)highPart << 32 | (uint)lowPart;
}

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top