我们如何以编程方式访问活动目录中的用户状态?特别 活动/离开/锁定等状态。这是建立一个Web快照,以查看所有登录用户及其各自的状态。
到目前为止,我可以搜索特定域下的所有用户,但没有找到他们当前状态的运气。
using (var context = new PrincipalContext(ContextType.Domain, "domain"))
{
using (var searcher = new PrincipalSearcher(new UserPrincipal(context)))
{
foreach (var result in searcher.FindAll())
{
DirectoryEntry de = result.GetUnderlyingObject() as DirectoryEntry;
Console.WriteLine("First Name: " + de.Properties["givenName"].Value);
Console.WriteLine("Last Name : " + de.Properties["sn"].Value);
Console.WriteLine("User principal name: " + de.Properties["userPrincipalName"].Value);
}
}
}
答案 0 :(得分:1)
“离开”不是你要从Active Directory中获得的东西。
您可以查看以下属性以获取您想要的一些信息: userAccountControl是您想要查看的主要属性。
在LDAP查询中使用(userAccountControl:AND:=2)
会找到已禁用的用户。
其他一些有用的属性是:
答案 1 :(得分:1)
您可以从每个工作站和域控制器上的安全日志中收集logon \ logoff用户事件。通过分析此信息,您可以确定当前活动的用户。不幸的是,该解决方案不适用于拥有数千个工作站和数百个DC的企业环境。有时,由于某种原因,安全日志中有时会缺少logon \ logoff事件。
如果使用lastLogon \ lastLogonTimestamp属性,请注意: