Casting ActiveDirectory pwdLastSet property without using ActiveDs

前端 未结 2 1523
轮回少年
轮回少年 2021-01-06 11:30

Ok. So I\'m trying to find a way to avoid including ActiveDs in my project because I\'m having trouble getting the dll to show up in the installer. The only reason to have i

2条回答
  •  旧巷少年郎
    2021-01-06 12:21

    You'll need to translate the AD Long Integer like this and you shouldn't need ActiveDs anymore:

    long pwdLastSet = CovertADSLargeIntegerToInt64(oUser.Properties["pwdLastSet"].Value);
    
    public static Int64 ConvertADSLargeIntegerToInt64(object adsLargeInteger)
    {
      var highPart = (Int32)adsLargeInteger.GetType().InvokeMember("HighPart", System.Reflection.BindingFlags.GetProperty, null, adsLargeInteger, null);
      var lowPart  = (Int32)adsLargeInteger.GetType().InvokeMember("LowPart",  System.Reflection.BindingFlags.GetProperty, null, adsLargeInteger, null);
      return highPart * ((Int64)UInt32.MaxValue + 1) + lowPart;
    }
    

提交回复
热议问题