Share via


Large Integer Property Type 

Active Directory schema properties such as lastLogon use the LargeInteger syntax type. For more information about the lastLogon property or the LargeInteger syntax type, see lastLogon or LargeInteger in the MSDN Library at https://msdn.microsoft.com/library.

If a property of this type is obtained with the Properties property, this data type is represented as a COM object that can be cast to an IADsLargeInteger. For more information about the IADsLargeInteger type, see IADsLargeInteger in the MSDN Library at https://msdn.microsoft.com/library.

If a property of this type is obtained from a ResultPropertyValueCollection, this data type is represented as an Int64 structure.

The following example shows how to convert from the IADsLargeInteger type to the DateTime type.

Imports System.DirectoryServices
Imports ActiveDs

Try

    Dim ent As New DirectoryEntry("LDAP://CN=My User Name,OU=Marketing,DC=fabrikam,DC=com")
    Dim myNumber As System.Int64 = 523442149523
    Dim LargeInt As New ActiveDs.LargeIntegerClass

    LargeInt.HighPart = CType((myNumber >> 32), Integer)
 
    myNumber = myNumber << 32
    myNumber = myNumber >> 32

    LargeInt.LowPart = (Convert.ToInt32(myNumber))
    ent.Properties("singleLargeInteger").Value = LargeInt
    ent.CommitChanges()

Catch e As Exception
    Console.WriteLine(e.ToString())

End Try
public static DateTime GetDateTimeFromLargeInteger(IADsLargeInteger largeIntValue)
{
    //
    // Convert large integer to int64 value
    //
    long int64Value = (long)((uint)largeIntValue.LowPart +
             (((long)largeIntValue.HighPart) << 32 ));  

    //
    // Return the DateTime in utc
    //
    return DateTime.FromFileTimeUtc(int64Value);
}

The following example shows how to convert from DateTime format to IADsLargeInteger.

Imports ActiveDs

Dim int64Val As IADsLargeInteger = CType(usr.Properties("lastLogon").Value, IADsLargeInteger)
If Not int64Val Is Nothing Then
    Dim largeInt As System.Int64 = int64Val.HighPart
    largeInt = largeInt << 32
    largeInt += int64Val.LowPart
    Console.WriteLine(largeInt)
End If
public static IADsLargeInteger GetLargeIntegerFromDateTime(DateTime dateTimeValue)
{
    //
    // Convert DateTime value to utc file time
    //
    Int64 int64Value = dateTimeValue.ToFileTimeUtc();

    //
    // convert to large integer
    //
    IADsLargeInteger largeIntValue = 
         IADsLargeInteger) new LargeInteger();
    largeIntValue.HighPart = (int) (int64Value >> 32);
    largeIntValue.LowPart = (int) (int64Value & 0xFFFFFFFF);

    return largeIntValue;
}