我想 a) 以编程方式和 b) 远程查找用户成功登录 Windows 计算机的最后日期/时间(通过远程桌面或控制台)。我愿意采用任何典型的 Windows 语言(C、C#、VB、批处理文件、JScript 等),但任何解决方案都很好。
尝试这个:
public static DateTime? GetLastLogin(string domainName,string userName)
{
PrincipalContext c = new PrincipalContext(ContextType.Domain,domainName);
UserPrincipal uc = UserPrincipal.FindByIdentity(c, userName);
return uc.LastLogon;
}
您需要添加对使用 System.DirectoryServices 的引用,并且
系统.目录服务.帐户管理
编辑:您也许可以通过执行以下操作来获取特定计算机的上次登录日期时间:
public static DateTime? GetLastLoginToMachine(string machineName, string userName)
{
PrincipalContext c = new PrincipalContext(ContextType.Machine, machineName);
UserPrincipal uc = UserPrincipal.FindByIdentity(c, userName);
return uc.LastLogon;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)