accountExpires Active Directory Attribute Get/Set

Setting the Active Directory AccountExpires Attribute: This is a handy reusable subroutine that you can put in your AD utilities.

I looked everywhere for this, I go pieces from other blogs, but could not find a good example that would SET the accountExpires Attribute well here it is enjoy...

Setting the Active Directory AccountExpires Attribute:

This is a handy reusable subroutine that you can put in your AD utilities.

 Public Sub ExpirePassword(ByVal de As DirectoryEntry, ByVal dte As String)

         'de is a directory entry after the user has been created
        'dte is string with date format "05/30/2008 5:00:00 PM"
         'for some reason it would populate 1 day earlier so I just added a day - it works well. hack, but it works :)


        de.Properties("accountExpires")(0) = GetLargeInteger(CType(CType(dte, Date).AddDays(1).ToFileTime, Int64))
         de.CommitChanges()

 

    End Sub

This helper function converts to a large adsi integer - from a couple different blogs not sure who's the owner...thanks,

Function GetLargeInteger(ByVal val As Int64) As IADsLargeInteger
        Dim largeInt As New ActiveDs.LargeIntegerClass

        largeInt.HighPart = CType((val >> 32), Integer)
        val = val << 32
        val = val >> 32
        largeInt.LowPart = (Convert.ToInt32(val))
        Return largeInt
    End Function

By Charles Stratton   Popularity  (3405 Views)
Biography - Charles Stratton
Active Directory Expert Active Directory Tools