![]() ![]() |
Current revision
GetActiveDirectoryFullName() FunctionReturn a string that represents what Active Directory has stored as the Full Name of an passed logon id (username) within the passed domain. SyntaxCODE GetActiveDirectoryName(strDomain, strUser)
Where strDomain is of type String and represents the domain to the searched; "strUser" is of type String and represents the username to be sought within the domain. CODE Public Function GetActiveDirectoryFullName(strDomain As String, strUsername As String) As String
' http://www.utteraccess.com/wiki/index.php/GetActiveDirectoryName ' Code courtesy of UtterAccess Wiki ' Licensed under Creative Commons License ' http://creativecommons.org/licenses/by-sa/3.0/ ' ' You are free to use this code in any application, ' provided this notice is left unchanged. ' ' rev date brief descripton ' 1.0 2013-01-30 Initial Release ' 'Connect to Active Directory Dim cnn As Object 'ADODB.Connection Set cnn = CreateObject("ADODB.Connection") cnn.Provider = "ADsDSOObject" cnn.Open "Active Directory Provider" 'Create the query Dim strSQL As String strSQL = "SELECT distinguishedName" & _ " FROM 'LDAP://" & strDomain & "'" & _ " WHERE objectCategory='user'" & _ " AND samAccountName = '" & strUsername & "'" 'Get the data and return the result Dim rst As Object 'ADODB.Recordset Set rst = cnn.Execute(strSQL, , 1) If Not rst.EOF Then _ GetActiveDirectoryFullName = Split(Mid(rst.Fields("distinguishedName"), Len("CN=") + 1), ",")(0) 'Close what we open. rst.Close cnn.Close End Function Return ValueString. ExampleFrom the Immediate Window: CODE ? GetActiveDirectoryFullName("someDomain","someUsername") someFirstname someLastname
|
![]()
Custom Search
|
![]() |
This page has been accessed 3,731 times. This page was last modified 21:41, 30 January 2013 by Brent Spaulding. Disclaimers |