活动目录AD 取用户过期时间accountExpires

今天整了一天时间,终于可以取到accountExpires

并转换为DateTime时间。

 

private long LongFromLargeInteger(object largeInteger)
    {
        System.Type type = largeInteger.GetType();
        int highPart = (int)type.InvokeMember("HighPart", System.Reflection.BindingFlags.GetProperty, null, largeInteger, null);
        int lowPart = (int)type.InvokeMember("LowPart", System.Reflection.BindingFlags.GetProperty, null, largeInteger, null);

        return (long)highPart << 32 | (uint)lowPart;
    }
    DateTime LargeIntToDateTime(ActiveDs.LargeInteger li)
    {
        long lTime;
        lTime = (long)li.HighPart;
        lTime <<= 32;
        lTime |= (uint)li.LowPart;
        return System.DateTime.FromFileTime(lTime);
    }

 

ActiveDs.LargeInteger pwdLastSet = child.Properties["pwdLastSet"].Value as ActiveDs.LargeInteger;

if ((accountExpires.HighPart == Int32.MaxValue) && (accountExpires.LowPart == -1))
{

//有效时间

//时间总是相差1天,所以我加了一个 -1

String dt=LargeIntToDateTime(accountExpires).AddDays(-1).ToString()
}

 

largeInteger 找不能命名空间了吧?

引用com 组件:Active DS Type Library

 

接下来设置这个属性,就比较方便了

 

using System.Reflection;

// Get the native object.
Type type = usr.NativeObject.GetType();
Object adsNative = usr.NativeObject;

// Use the Type.InvokeMember method to invoke the
// AccountExpirationDate property setter.
type.InvokeMember(
    "AccountExpirationDate",
    BindingFlags.SetProperty,
    null,
    adsNative,
    new object[]{"12/29/2004"});

// Commit the changes.
usr.CommitChanges();

The following C# example shows how to use the InvokeSet method to set the value of the IADsUser.AccountExpirationDate property.

// Use the DirectoryEntry.InvokeSet method to invoke the
// AccountExpirationDate property setter.
usr.InvokeSet(
    "AccountExpirationDate",
    new object[] {new DateTime(2005, 12, 29)});

// Commit the changes.
usr.CommitChanges();

 

转载于:https://www.cnblogs.com/jamin/archive/2011/08/12/2136506.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值