我搜索了很长时间如何定义组上允许的登录时间,就像可以从 Active Directory 中的帐户选项卡中使用用户一样。
我已经在 c# 中有一个类,它可以使用帮助“logonhours”属性进行查询以返回用户所有允许的时间列表。
public byte[] GetLogonHours(string userName, string password, string path)
{
DirectoryEntry entry = this.GetUserAccount(userName, path);
return (byte[])entry.Properties["logonHours"].Value;
}
public DirectoryEntry GetUserAccount(string username, string path)
{
using (DirectoryEntry objRootEntry = new DirectoryEntry(path))
{
using (DirectorySearcher objAdSearcher = new DirectorySearcher(objRootEntry))
{
objAdSearcher.Filter = "(&(objectClass=user)(samAccountName=" + username + "))";
SearchResult objResult = objAdSearcher.FindOne();
if (objResult != null)
{
return objResult.GetDirectoryEntry();
}
}
}
return null;
}
我使用这篇文章来帮助我了解如何查询登录时间:
重要的是要了解我不希望某个功能知道用户上次登录的时间。我有一个功能,可以防止用户在某些时候登录。
我想要的是一个可以为一组用户应用登录时间的功能,我可以使用 c# 查询 Active Directory 以获取这些登录时间信息。
非常感谢你。