更新时间:2023-02-15 21:10:13
有两种方法可以通过 .NET 检索 uSNChanged
属性:
There are two ways to retrieve the uSNChanged
property via .NET:
包含对 COM 库的引用:Active DS 类型库",然后您需要使用 IADsLargeInterger
检索该值,最后将其转换为 long代码>.例如:
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# 翻译值.感谢 Simon Gilbee,我们有这个选项:
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;
}
我强烈建议您使用选项 #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.