IADsLargeInteger Namespace

I am looking for a way to convert a COM object to DateTime, and I have seen many articles about this problem (for example, this https://msdn.microsoft.com/en-us/library/ms180872(v=vs.80).aspx and this- How to read the "uSNChanged" property using C # )

However, all of these articles talk about using an object from an interface IADsLargeInteger.

I tried to find the namespace of this interface, and I just could not find the hints.

+4
source share
2 answers

Here is a sample code that includes everything you need to convert from an AD type to a DateTime:

using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;
using ActiveDs; // Namespace added via ref to C:\Windows\System32\activeds.tlb

private DateTime? getLastLogin(DirectoryEntry de)
{
    Int64 lastLogonThisServer = new Int64();

    if (de.Properties.Contains("lastLogon"))
    {
        if (de.Properties["lastLogon"].Value != null)
        {
            try
            {
                IADsLargeInteger lgInt =
                (IADsLargeInteger) de.Properties["lastLogon"].Value;
                lastLogonThisServer = ((long)lgInt.HighPart << 32) + lgInt.LowPart;

                return DateTime.FromFileTime(lastLogonThisServer);
            }
            catch (Exception e)
            {
                return null;
            }
        }
    }
    return null;
}
+7
source

, IADsLargeInteger, , COM-, .

COM- :

[ComImport, Guid("9068270b-0939-11d1-8be1-00c04fd8d503"), InterfaceType(ComInterfaceType.InterfaceIsDual)]
internal interface IAdsLargeInteger
{
    long HighPart
    {
        [SuppressUnmanagedCodeSecurity] get; [SuppressUnmanagedCodeSecurity] set;
    }

    long LowPart
    {
        [SuppressUnmanagedCodeSecurity] get; [SuppressUnmanagedCodeSecurity] set;
    }
}

:

var largeInt = (IAdsLargeInteger)directoryEntry.Properties[propertyName].Value;
var datelong = (largeInt.HighPart << 32) + largeInt.LowPart;
var dateTime = DateTime.FromFileTimeUtc(datelong);

, , ADSI

0

Source: https://habr.com/ru/post/1612689/


All Articles