문제

디렉토리 서비스 객체의 "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

해당 시스템을 어떻게 변환합니까 .__ comobject는 int64로 어떻게 변환합니까?


사용 된 솔루션 :

이것은 아래의 marc_s의 솔루션을 기반으로 사용한 솔루션입니다.

    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;

내가 알 수있는 한, 이것은 잘 작동해야합니다.

마크

다른 팁

그것은 그것이있는 것처럼 보입니다 IADSLARGEINTEGER 유형이 있으므로 값을 추출하려면 약간의 interop 마술이 필요합니다. 이 스레드 샘플 VB 구현이 포함되어 있으며 자신과 유사한 문제를 언급하지만 지금은 그 유용성을 확인할 수있는 곳은 거의 없습니다. 도움이 되었기를 바랍니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top