Some properties are returned as a Generic COM wrapper object __ComObj,
because:
1) They are not declared in the System.DirectoryServices namespace classes,
2) or there is no Typelib declaration for the corresponding to the COM
interface
You have three options to solve this issue using C#.
a) Use reflection to read the properties of the underlying COM interface,
b) Import the activeds.tlb in your project (add a COM reference).
Following illustrates how to retrieve the usnCreated attribute using option
a):
if(Marshal.IsComObject(pcoll["usnCreated"].Value)) // is __ComObj?
{
object obj = pcoll["usnCreated"].Value; // __ComObj derives from
Object
// Get LowPart property from ILargeInteger (INTEGER8 adstype)
object low = obj.GetType().InvokeMember("LowPart",
BindingFlags.GetProperty,null, obj, null);
// Get HighPart property from ILargeInteger (INTEGER8 adstype)
object high = obj.GetType().InvokeMember("HighPart",
BindingFlags.GetProperty,null, obj, null);
// Convert to long
long usn = (Convert.ToInt64(high) << 32) + Convert.ToInt64(low);
Console.WriteLine(usn);
}
And this shows how get the accountExpires property (or any other
LargeInteger property representing a date) using b)
....
using activedsImport; // Imported activds.tlb Interop assembly's
namespace
.....
LargeInteger li = pcoll["accountExpires"].Value as LargeInteger;
long date = (((long)(li.HighPart) << 32) + (long) li.LowPart);
if((li.HighPart == -1) && (li.LowPart == -1)) {
Console.WriteLine("Account never expires");
}
else {
// Valid date, convert to DateTime format
// Note that this date is one day later than the date displayd in the
Directory Users and Computers MMC
string dt = DateTime.FromFileTime(date).ToString();
Console.WriteLine("DATE = {0:D}" ,dt);
}
Willy.
"Gary K" <__*****@trcare.org.au__> wrote in message
news:85**********************************@microsof t.com...
Ok, I've disected the objects and they appear to be of the generic Object
class. When I use GetMethods/Members/Properties I get the following list
for both Members & Methods while there does not appear to be any
properties. My questions still stand though, how can I manipulate these
objects and get some meaningful data from them? I've listed the Active
Directory properties where these objects appear as well.
Method/Member list:
CreateObjRef
InitializeLifetimeService
GetLifetimeService
GetHashCode
Equals
ToString
GetType
AD Property List - (from objectClass=user):
uSNCreated
uSNChanged
badPasswordTime
lastLogoff
lastLogon
pwdLastSet
accountExpires
nTSecurityDescriptor