首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >确定AD中的计算机是否有用户登录

确定AD中的计算机是否有用户登录
EN

Stack Overflow用户
提问于 2012-05-29 19:42:15
回答 2查看 2.5K关注 0票数 1

我正在尝试接收当前连接到AD的所有计算机,以及其中哪些计算机具有登录到AD的用户。我尝试过使用ComputerPrincipal.LastLogon属性,但得到的值是完全关闭的,大约一周。

我想知道AD中哪些计算机是可用的。有没有别的方法可以用呢?

代码语言:javascript
复制
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "192.168.0.101:389", "Administrator", "XXXX");

// define a "query-by-example" principal - here, we search for a ComputerPrincipal 
ComputerPrincipal qbeComputer = new ComputerPrincipal(ctx);

// create your principal searcher passing in the QBE principal    
PrincipalSearcher srch = new PrincipalSearcher(qbeComputer);

// find all matches
foreach (var found in srch.FindAll())
{
    // do whatever here - "found" is of type "Principal" - it could be user, group, computer.....          
    ComputerPrincipal cp = found as ComputerPrincipal;

    if (cp != null)
    {
       string computerName = cp.Name;
       DateTime? lastLogon = new DateTime();
       lastLogon = cp.LastLogon;
       DateTime convertedDate = DateTime.SpecifyKind(DateTime.Parse(cp.LastLogon.ToString()), DateTimeKind.Utc);

       var kind = convertedDate.Kind;
       DateTime dt = convertedDate.ToLocalTime();

       Response.Write(cp.Name+"   :   "+ dt.ToString()+ "<br />");
    }
 }

编辑:

我希望打印结果是这样的:

计算机1:真计算机2:假计算机3:假计算机4:真

如果计算机当前已登录,是否无法查询该计算机?我只需要一个布尔值,真或假。

EN

回答 2

Stack Overflow用户

发布于 2012-05-29 20:19:53

这是一个经典的MCSE问题。lastlogon字段是特定DC的本地字段,不是全局复制的。

您需要查询每个AD域控制器,并查找每个控制器的最新日期。

票数 0
EN

Stack Overflow用户

发布于 2012-05-29 20:29:56

您需要查询林/域中所有域控制器上的安全事件日志,以确保用户已登录到某些machine.Then。您应该使用WMI与此工作站联系,以检查用户是否仍在登录。

您可能感兴趣事件是交互式登录类型的Logon events (ID4624表示登录,4634表示注销)。

但是,当PC失去与域(笔记本电脑很常见)的连接并且用户注销时,没有域控制器会收到注销事件。

用户可以实际登录,而无需事先在PC上创建其帐户的本地缓存的域。

正如其他人所说的,lastlogon和lastlogontimestamp不能用来可靠地跟踪用户登录,请检查thisthis

一些示例here

更多信息herehere

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10798437

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档