-1

當我們想從Active Directory填充用戶詳細信息時,有需要。共享我的代碼以訪問來自AD的用戶詳細信息。在VB腳本中從Active Directory獲取網絡詳細信息?

+0

[相關](http://www.planetcobalt.net/sdb/adquery.shtml)。 –

+1

這可能會收集一些downvotes - 自我回答的問題與其他人一樣,包括研究,努力,問題的清晰度等。 – Plutonix

回答

0

介紹

人們經常問的通過傳遞網絡帳戶名稱或電子郵件查詢Active Directory。有很多文章可以在這裏找到,有人可能會感到困惑。以下是從活動目錄數據庫訪問用戶詳細信息的簡單工作代碼 - 請注意,爲了訪問AD,您必須指定連接中的有效網絡帳戶憑據。

function GetADDetails(userId) 
    Set objConn = Server.CreateObject("ADODB.Connection") 
    objConn.provider ="ADsDSOObject" 
    objConn.Properties("User ID") = "domain\userId" 'specify domain and 
    network account 
    objConn.Properties("Password") = "password" 'specify network password 
    objConn.Properties("Encrypt Password") = True 
    objConn.open "Active Directory Provider" 
    Set objCom = CreateObject("ADODB.Command") 
    Set objCom.ActiveConnection = objConn 
    strTarget="GC://abc.com" 'your domain name 
    objCom.CommandText ="select sn, givenName, sAMAccountName, name,mail,  
    telephoneNumber FROM '"+strTarget+"' where sAMAccountname='"+userId+"'" 
    Set objRS = objCom.Execute 
    If Not (objRS.EOF Or objRS.BOF) Then 
    GetADDetails=objRS.GetRows 
    Else 
    GetUserData = Null 
    End If 
    'Close objects and remove from memory 
    objRS.Close 
    objConn.Close 
    Set objRS = Nothing 
    Set objConn = Nothing 
    Set objCom = Nothing 
end function