G
Guest
I'm trying to convert the value of 'lastLogon' to a DateTime value by using
the code listed below, but the code doesn't seem to be working for it throws
an exception: 'The object's type must be__ComObject or derived from
__ComObject...' right at the CreateWrapperOfType() function. Any ideas as to
what I'm doing wrong?
using System;
using System.DirectoryServices;
using System.Runtime.InteropServices;
using ActiveDs;
entry = new DirectoryEntry("LDAP://MyDomain.com/dc=MyDomain, dc=com");
dSearch = new DirectorySearcher(entry);
dSearch.Filter = "(objectClass=computer)";
foreach(SearchResult results in dSearch.FindAll())
{
foreach(string Key in results.Properties.PropertyNames)
{
if(results.Properties[Key]!=null)
{
if(Key.ToUpper()=="LASTLOGON")
{
LargeIntegerClass li;
li =
(LargeIntegerClass)Marshal.CreateWrapperOfType(results.Properties["lastLogon"][0], typeof(LargeIntegerClass));
long int64Value = (long)((uint)li.LowPart + (((long)li.HighPart) << 32 ));
Marshal.ReleaseComObject(li);
this.listBox1.Items.Add("Last logged on at:
"+DateTime.FromFileTimeUtc(int64Value).ToLongDateString());
}
}
}
}
the code listed below, but the code doesn't seem to be working for it throws
an exception: 'The object's type must be__ComObject or derived from
__ComObject...' right at the CreateWrapperOfType() function. Any ideas as to
what I'm doing wrong?
using System;
using System.DirectoryServices;
using System.Runtime.InteropServices;
using ActiveDs;
entry = new DirectoryEntry("LDAP://MyDomain.com/dc=MyDomain, dc=com");
dSearch = new DirectorySearcher(entry);
dSearch.Filter = "(objectClass=computer)";
foreach(SearchResult results in dSearch.FindAll())
{
foreach(string Key in results.Properties.PropertyNames)
{
if(results.Properties[Key]!=null)
{
if(Key.ToUpper()=="LASTLOGON")
{
LargeIntegerClass li;
li =
(LargeIntegerClass)Marshal.CreateWrapperOfType(results.Properties["lastLogon"][0], typeof(LargeIntegerClass));
long int64Value = (long)((uint)li.LowPart + (((long)li.HighPart) << 32 ));
Marshal.ReleaseComObject(li);
this.listBox1.Items.Add("Last logged on at:
"+DateTime.FromFileTimeUtc(int64Value).ToLongDateString());
}
}
}
}