如何阅读" uSNChanged"使用C#属性 [英] How to read "uSNChanged" property using C#

查看:509
本文介绍了如何阅读" uSNChanged"使用C#属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用C#来获得,通过在ActiveDirectory中的 uSNChanged 值的最后修改或创建的属性...我也试图找到<$ C的最大值$ C> uSNChanged ,你能不能帮我找出解决办法?谢谢

I want to get the last modified or created attributes via the uSNChanged value in ActiveDirectory using C# ... I was also trying to find the max value of uSNChanged, can you help me to find out the solution? Thanks

推荐答案

有两种方式来获取通过.NET中的 uSNChanged 属性:

There are two ways to retrieve the uSNChanged property via .NET:

  1. 中提及一个COM库:活动DS类型库,那么你就需要使用 IADsLargeInterger 检索值,并最终将其转换为一个例如

  1. Include a reference to a COM library: "Active DS Type Library", then you need to use the IADsLargeInterger to retrieve the value and finally convert it to a long. For example:

IADsLargeInteger li_ad = (IADsLargeInteger)oUser.Properties["USNChanged"].Value;
long l_uChanged = GetLongFromLargeInteger( li_ad );

static long GetLongFromLargeInteger(  IADsLargeInteger  Li )
{
    long retval = Li.HighPart;
    retval <<=32;
    retval |=(uint)Li.LowPart;
    return retval;
}

  • 翻译只能使用C#中的值。感谢<一href="http://stackoverflow.com/questions/1101022/how-to-change-system-directoryentry-usnchanged-attribute-value-to-an-int64">Simon Gilbee ,我们有这个选项:

  • Translate the values only using C#. Thanks to Simon Gilbee, we have this option:

    long usnChanged = CovertADSLargeIntegerToInt64(oUser.Properties["USNChanged"].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;
    }
    

  • 我强烈建议你去与选项#2 以避免与旧的问题ActiveDs库,他们不必回答过的此列表

    I highly recommend you go with Option #2 to avoid problems with the legacy ActiveDs library and won't need answers off this list.

    这篇关于如何阅读&QUOT; uSNChanged&QUOT;使用C#属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆