Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to change System.DirectoryEntry "uSNChanged" attribute value to an Int64
    text
    copied!<p>I'm trying to get the Int64 value of a Directory Services object's "uSNChanged" value. Unfortunately, it is always coming back as a COM object of some kind. I've tried using casting to Int64, calling Int64.Parse(), and calling Convert.ToInt64(). None of these work.</p> <p>For a given DirectoryEntry object, this code will display the properties:</p> <pre><code> 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); } } </code></pre> <p>This is the output:</p> <pre> 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 </pre> <p>How do I convert that System.__ComObject into a Int64?</p> <hr/> <h2>Solution Used:</h2> <p>This is the solution I used based on marc_s's solution below:</p> <pre><code> 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; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload