IADsLargeInteger的名称空间 [英] The namespace of IADsLargeInteger
问题描述
我正在寻找将 COM对象转换为 DateTime
的方法,我看到了很多有关
这个问题的文章(像这样)一个- https://msdn.microsoft.com /en-us/library/ms180872(v=vs.80).aspx
和这个
如何使用C#读取 uSNChanged属性)
I looking for way to convert COM object to DateTime
and I saw a lot of articles about this problem
(like this one -https://msdn.microsoft.com/en-us/library/ms180872(v=vs.80).aspx
and this one-
How to read "uSNChanged" property using C# )
这些文章中讨论了如何从接口 IADsLargeInteger
使用对象。
However, all of those articles talking about using an object from the interface IADsLargeInteger
.
我试图寻找该对象的命名空间界面,我只是找不到任何线索。
I tried to look for the namespace of this interface and I just couldn't find any clue.
推荐答案
下面是一个代码示例,其中包括您需要从AD转换的所有内容键入DateTime:
Here is a code sample including everything you need to convert from the AD type to a DateTime:
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;
using ActiveDs; // Namespace added via ref to C:\Windows\System32\activeds.tlb
private DateTime? getLastLogin(DirectoryEntry de)
{
Int64 lastLogonThisServer = new Int64();
if (de.Properties.Contains("lastLogon"))
{
if (de.Properties["lastLogon"].Value != null)
{
try
{
IADsLargeInteger lgInt =
(IADsLargeInteger) de.Properties["lastLogon"].Value;
lastLogonThisServer = ((long)lgInt.HighPart << 32) + lgInt.LowPart;
return DateTime.FromFileTime(lastLogonThisServer);
}
catch (Exception e)
{
return null;
}
}
}
return null;
}
这篇关于IADsLargeInteger的名称空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!