据我所知,在.net没有方法直接通过获取属性的方法获得AD上密码失效的时间.要通过用户属性pwdLastSet(密码最后设置时间)和域属性maxPwdAge(密码最大寿命)这两个属性值计算获得.

pwdLastSet属性值可以通过如下代码获得,但是怎么获得maxPwdAge这个属性值,请高手相助?

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Runtime.InteropServices;
using System.DirectoryServices;
namespace expiredate
{
    
/// 
    
/// WebForm1 的摘要说明。
    
/// 

    
///ActiveDs.tlb

    public class WebForm1 : System.Web.UI.Page
    
{        
        
protected System.Web.UI.WebControls.TextBox TextBox1;
        
protected System.Web.UI.WebControls.TextBox TextBox2;
        
protected System.Web.UI.WebControls.TextBox TextBox3;
        
protected System.Web.UI.WebControls.Button Button1;
        [ComImport]
        [Guid(
"9068270B-0939-11D1-8BE1-00C04FD8D503")]
        [InterfaceType(ComInterfaceType.InterfaceIsDual)]
        
internal interface IADsLargeInteger
        
{
            [DispId(
0x00000002)]
            
int HighPart...{getset;}
            [DispId(
0x00000003)]
            
int LowPart...{getset;}
        }

        
private void Button1_Click(object sender, System.EventArgs e)
        
{
            
string ADUser = "1111111111111";
            
string ADPassword = "22222222";
            
string ADPath="LDAP://....";    
            
try
            
{
                 System.DirectoryServices.DirectoryEntry mUser 
=
                                                                         new System.DirectoryServices.DirectoryEntry(ADPath,ADUser,ADPassword);
                 mUser.RefreshCache();
                 
if(mUser.Properties.Contains("pwdLastSet"))
                        
{                                           
                                  IADsLargeInteger li 
=(IADsLargeInteger)mUser.Properties["pwdLastSet"][0];              
                            
long date = (long)li.HighPart << 32 | (uint)li.LowPart;
                             DateTime time 
= DateTime.FromFileTime(date);
                            
this.TextBox1.Text=time.ToString();
                           }

                   }

          }

}


posted on 2005-10-21 15:22  花光月影  阅读(1540)  评论(3编辑  收藏  举报