C# 使用Active Directory的组上允许的登录小时数
我花了很长时间研究如何定义组上允许的登录时间,就像从Active Directory中的“帐户”选项卡处理用户一样 我已经有了一个c#类,它可以通过帮助“logonhours”属性查询并返回用户所有允许的小时数列表C# 使用Active Directory的组上允许的登录小时数,c#,templates,active-directory,group-policy,gpo,C#,Templates,Active Directory,Group Policy,Gpo,我花了很长时间研究如何定义组上允许的登录时间,就像从Active Directory中的“帐户”选项卡处理用户一样 我已经有了一个c#类,它可以通过帮助“logonhours”属性查询并返回用户所有允许的小时数列表 public byte[] GetLogonHours(string userName, string password, string path) { DirectoryEntry entry = this.GetUserAccount(userName, pat
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以获取这些登录时间信息
非常感谢。根据,您应该生成组中用户的列表,并将其登录时间写入CSV文件。根据,您应该生成组中用户的列表,并将其登录时间写入CSV文件。据我所知,登录时间信息是一种用户信息。如@Knite中所述,您可以更改它:
在您的情况下,您可以循环查找组中的所有成员并更改他们的登录时间。在我的理解中,登录时间信息是一种用户信息。如@Knite中所述,您可以更改它: