转:读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。


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

InBlock.gif        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif          
long lastChanged;
InBlock.gif
InBlock.gif          
try
ExpandedSubBlockStart.gifContractedSubBlock.gif          
dot.gif{
InBlock.gif            lastChanged 
= GetLongValue((IADsLargeInteger)Properties["pwdLastSet"][0]);
ExpandedSubBlockEnd.gif          }

InBlock.gif          
catch(Exception)
ExpandedSubBlockStart.gifContractedSubBlock.gif          
dot.gif{
InBlock.gif            
return DateTime.MinValue; // 密码没有被设置过
ExpandedSubBlockEnd.gif
          }

InBlock.gif
InBlock.gif          IADsLargeInteger maxAge 
= (IADsLargeInteger)Server.Properties["maxPwdAge"][0];
InBlock.gif
InBlock.gif          
if(maxAge.LowPart == 0)
InBlock.gif            
return DateTime.MaxValue; // 域中密码没有设置最大有效期限
InBlock.gif
          else
InBlock.gif            
return PasswordLastChanged.AddDays(Server.MaxPasswordDays);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif      }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif  }
 
None.gif 
None.gif
None.gif

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

None.gif

用户是否可以远程登录属性的读取方法:
引用名称空间: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).

转载于:https://www.cnblogs.com/skyfei/archive/2005/04/27/146384.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值