gpt4 book ai didi

active-directory - 如何将 System.DirectoryEntry "uSNChanged"属性值更改为 Int64

转载 作者:行者123 更新时间:2023-12-04 07:22:16 25 4
gpt4 key购买 nike

我正在尝试获取目录服务对象的“uSNChanged”值的 Int64 值。不幸的是,它总是作为某种 COM 对象回来。我尝试使用转换为 Int64、调用 Int64.Parse() 和调用 Convert.ToInt64()。这些都不起作用。

对于给定的 DirectoryEntry 对象,此代码将显示属性:

    private static void DisplaySelectedProperties(DirectoryEntry objADObject)
{
try
{
string[] properties = new string[] {
"displayName",
"whenCreated",
"whenChanged",
"uSNCreated",
"uSNChanged",
};

Console.WriteLine(String.Format("Displaying selected properties of {0}", objADObject.Path));
foreach (string strAttrName in properties)
{
foreach (var objAttrValue in objADObject.Properties[strAttrName])
{
string strAttrValue = objAttrValue.ToString();
Console.WriteLine(String.Format(" {0, -22} : {1}", strAttrName, strAttrValue));
}
}
Console.WriteLine();
}
catch (Exception ex)
{
throw new ApplicationException(string.Format("Fatal error accessing: {0} - {1}", objADObject.Path, ex.Message), ex);
}
}

这是输出:
Displaying selected properties of LDAP://server/o=org/cn=obj   displayName            : Display Name   whenCreated            : 7/8/2009 7:29:02 PM   whenChanged            : 7/8/2009 10:42:23 PM   uSNCreated             : System.__ComObject   uSNChanged             : System.__ComObject

How do I convert that System.__ComObject into a Int64?


Solution Used:

This is the solution I used based on marc_s's solution below:

    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;
}

最佳答案

我在我的 ADSI 浏览器中使用了这段代码 BeaverTail这是用 C# 编写的:

Int64 iLargeInt = 0;

IADsLargeInteger int64Val = (IADsLargeInteger)oPropValue.LargeInteger;
iLargeInt = int64Val.HighPart * 4294967296 + int64Val.LowPart;

据我所知,这应该可以正常工作。

马克

关于active-directory - 如何将 System.DirectoryEntry "uSNChanged"属性值更改为 Int64,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1101022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com