Casting ActiveDirectory pwdLastSet property without using ActiveDs

前端 未结 2 1519
轮回少年
轮回少年 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:09

    What is wrong with this code? It should work fine:

        SearchResult sr = ds.FindOne(); 
        hacked = DateTime.FromFileTime((long)sr.Properties["pwdLastSet"][0]); 
    
    0 讨论(0)
  • 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;
    }
    
    0 讨论(0)
提交回复
热议问题