How to read quot;uSNChangedquot; property using C#(如何阅读“uSNChanged使用 C# 的属性)
问题描述
我想使用 C# 通过 ActiveDirectory 中的 uSNChanged 值获取最后修改或创建的属性......我还试图找到 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:
包含对 COM 库的引用:Active DS 类型库",然后您需要使用
IADsLargeInterger检索该值,最后将其转换为long代码>.例如:
Include a reference to a COM library: "Active DS Type Library", then you need to use the
IADsLargeIntergerto retrieve the value and finally convert it to along. 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.
这篇关于如何阅读“uSNChanged"使用 C# 的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何阅读“uSNChanged"使用 C# 的属性
- 在 C# 中异步处理项目队列 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- 使用 rss + c# 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
