活动目录AD 取用户过期时间accountExpires
今天整了一天时间,终于可以取到accountExpires
并转换为DateTime时间。
private long LongFromLargeInteger(object largeInteger)
{
System.Type type = largeInteger.GetType();
int highPart = (int)type.InvokeMember("HighPart", System.Reflection.BindingFlags.GetProperty, null, largeInteger, null);
int lowPart = (int)type.InvokeMember("LowPart", System.Reflection.BindingFlags.GetProperty, null, largeInteger, null);
return (long)highPart << 32 | (uint)lowPart;
}
DateTime LargeIntToDateTime(ActiveDs.LargeInteger li)
{
long lTime;
lTime = (long)li.HighPart;
lTime <<= 32;
lTime |= (uint)li.LowPart;
return System.DateTime.FromFileTime(lTime);
}
ActiveDs.LargeInteger pwdLastSet = child.Properties["pwdLastSet"].Value as ActiveDs.LargeInteger;
if ((accountExpires.HighPart == Int32.MaxValue) && (accountExpires.LowPart == -1))
{
//有效时间
//时间总是相差1天,所以我加了一个 -1
String dt=LargeIntToDateTime(accountExpires).AddDays(-1).ToString()
}
largeInteger 找不能命名空间了吧?
引用com 组件:Active DS Type Library
接下来设置这个属性,就比较方便了
using System.Reflection;
// Get the native object.
Type type = usr.NativeObject.GetType();
Object adsNative = usr.NativeObject;
// Use the Type.InvokeMember method to invoke the
// AccountExpirationDate property setter.
type.InvokeMember(
"AccountExpirationDate",
BindingFlags.SetProperty,
null,
adsNative,
new object[]{"12/29/2004"});
// Commit the changes.
usr.CommitChanges();
The following C# example shows how to use the InvokeSet method to set the value of the IADsUser.AccountExpirationDate property.
// Use the DirectoryEntry.InvokeSet method to invoke the
// AccountExpirationDate property setter.
usr.InvokeSet(
"AccountExpirationDate",
new object[] {new DateTime(2005, 12, 29)});
// Commit the changes.
usr.CommitChanges();
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
· AI 智能体引爆开源社区「GitHub 热点速览」
2009-08-12 Applet数字签名,授予访问本地资源,读写权限设置
2008-08-12 拒绝破解,用10大免费软件来代替盗版