zoukankan      html  css  js  c++  java
  • 转:读AD里特殊的属性in C#

    摘自from:http://www.cnblogs.com/flier/archive/2004/10/21/55266.html?Pending=true#Post

    AD里的一些属性:"accountExpires", "pwdLastSet" 等,在ADSIEDIT.msc中查看类型为LargerInteger,但不能通过DirectoryEntry属性直接读出,读他人一篇blog得到解决方法。添加com引用using ActiveDs;使用ActiveDs里的类型,强制转化属性的value为IADsLargeInteger类型,在调用GetLongValue方法转为long型,下面代码拷贝自引用blog。


    public class AdUser : AdItem
      
    {
        
    // http://msdn.microsoft.com/library/en-us/dnclinic/html/scripting09102002.asp
        public DateTime PasswordExpirationDate
        
    {
          
    get
          
    {
            
    if(IsPasswordNotExpire)
            
    {
              
    return DateTime.MaxValue; // 帐号被设置为密码永不过期
            }

            
    else
            
    {
              
    long lastChanged;

              
    try
              
    {
                lastChanged 
    = GetLongValue((IADsLargeInteger)Properties["pwdLastSet"][0]);
              }

              
    catch(Exception)
              
    {
                
    return DateTime.MinValue; // 密码没有被设置过
              }


              IADsLargeInteger maxAge 
    = (IADsLargeInteger)Server.Properties["maxPwdAge"][0];

              
    if(maxAge.LowPart == 0)
                
    return DateTime.MaxValue; // 域中密码没有设置最大有效期限
              else
                
    return PasswordLastChanged.AddDays(Server.MaxPasswordDays);
            }

          }

        }

      }
     
     


    internal long GetLongValue(IADsLargeInteger value)
      
    {
        
    // 将 IADsLargeInteger 内容转换为 long 之前必须小心溢出
        
    // http://www.rlmueller.net/Integer8Discussion.htm
        return (long)(((ulong)value.HighPart << 32+ (uint)value.LowPart);
      }


    用户是否可以远程登录属性的读取方法:
    引用名称空间:using TSUSEREXLib;
    先将DirectoryEntry 变成基本的adsi类型,然后再定义为IADsTSUserEx类型,在调用里面的方法。
    object objAD = userDEntry.NativeObject ;
       int k = ((IADsTSUserEx)objAD).AllowLogon;

    //Value that specifies whether to allow remote observation or remote control of the user's
       //Terminal Services session. Values include: "Disable" (0), "EnableInputNotify" (1),
       //"EnableInputNoNotify" (2), "EnableNoInputNotify" (3), and "EnableNoInputNoNotify" (4).
  • 相关阅读:
    CentOS安装Hadoop
    数据仓库、数据湖、流批一体,终于有大神讲清楚了!
    AIOps, ITOps, and IT Monitoring 2020 Predictions
    AIOps in 2020: A Beginner’s Guide
    RCA Models Notes
    故障自愈:解决运维的主要矛盾才能AIOps
    WHAT IS ROOT CAUSE ANALYSIS (RCA)?
    Survey of Automated Market Making Algorithms
    清华裴丹:我在智能运维科研领域的一些思考
    RSA2017浅谈下一代应用及IT基础设施的安全管理模式——DEVSECOPS
  • 原文地址:https://www.cnblogs.com/skyfei/p/146384.html
Copyright © 2011-2022 走看看