locked
How to set accountExpires property without ActiveDS? RRS feed

  • Question

  • I wrote a little program to manage an Active Directory and when I create accounts I have to setup that they expire after 500 days.
    I set this up with this function (which I found on the internet):

    public static IADsLargeInteger GetLargeIntegerFromDateTime( DateTime dateTimeValue ) 
            { 
                Int64 int64Value = dateTimeValue.ToFileTimeUtc(); 
                IADsLargeInteger largeIntValue = (IADsLargeInteger) new LargeInteger(); 
                largeIntValue.HighPart = (int)(int64Value >> 32); 
                largeIntValue.LowPart  = (int)(int64Value & 0xFFFFFFFF); 
                return largeIntValue; 
            } 

    like this:

    directoryEntry.Properties["accountExpires"].Value = GetLargeIntegerFromDateTime(DateTime.Now.AddDays(500)); 

    For this to work I have to have "Interop.ActiveDs.dll" in the same directory ____ my app, and I don't want this.

    I created a little function which does the same thing ____ the one above, but the number it returns is not IADsLargeInteger:

            private long getExpireDate(DateTime date) 
            { 
                long time = date.ToFileTimeUtc(); 
                long time1 = time >> 32; 
                time1 = time1 << 32; 
                long time2 = time & 0x00000000FFFFFFFF; 
                return time1 + time2; 
            } 

    Is there a way I can cast, or convert the integer I get from
    getExpireDate to assigned the accountExpires value without using ActiveDS.
    In .Net 3.5 there is a new UserPrincipal class which has AccountExpirationDate field which you just assigned DateTime and it isn't using ActiveDS.

    Is there a way this could be done?

    P.S. I don't want to use .Net 3.5, I want all to be in 2.0 :)

    • Edited by kustodian Friday, July 18, 2008 5:46 PM bad spelling
    • Moved by jack 321 Wednesday, July 23, 2008 3:13 AM off topic for C#
    Friday, July 18, 2008 5:44 PM

Answers