我希望你能帮我使用C#通过uSNChanged
的值在ActiveDirectory中获取最近修改或创建的属性...我还尝试找到uSNChanged
的最大值,你能帮我找到解决方案吗?谢谢。
我希望你能帮我使用C#通过uSNChanged
的值在ActiveDirectory中获取最近修改或创建的属性...我还尝试找到uSNChanged
的最大值,你能帮我找到解决方案吗?谢谢。
通过.NET有两种方法检索uSNChanged
属性:
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;
}
Translate the values only using C#. Thanks to Simon Gilbee, we have this option:
long usnChanged = ConvertADSLargeIntegerToInt64(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;
}