By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,022 Members | 1,379 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,022 IT Pros & Developers. It's quick & easy.

COM Objects

P: n/a
I'm retrieving all the properties from a DirectoryEntry object and some of the properties are __ComObjects. How can I handle these in my code? Basically, I want to display the values in HRF (human readable format). I'm pretty sure that the values I'm dealing with are date/times but I'm not sure, so I will have to check the type as well.
Nov 22 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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
CreateObjRe
InitializeLifetimeServic
GetLifetimeServic
GetHashCod
Equal
ToStrin
GetTyp

AD Property List - (from objectClass=user)
uSNCreate
uSNChange
badPasswordTim
lastLogof
lastLogo
pwdLastSe
accountExpire
nTSecurityDescriptor
Nov 22 '05 #2

P: n/a
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
CreateObjRe
InitializeLifetimeServic
GetLifetimeServic
GetHashCod
Equal
ToStrin
GetTyp

AD Property List - (from objectClass=user)
uSNCreate
uSNChange
badPasswordTim
lastLogof
lastLogo
pwdLastSe
accountExpire
nTSecurityDescriptor
Nov 22 '05 #3

P: n/a
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

Nov 22 '05 #4

P: n/a
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

Nov 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.