Jump to content

get email address from network user name


Paco

Recommended Posts

Deal All,

I really hope that someone can help on it

 

I would like, from a user name to get the corresponding e-mail address

 

the idea is to provide to my VI:

  • domain name
  • user name
  • eventually the password if really necessary

and get as result the e-mail address.

In attachment you can see what I already try by using the .NET System.DirectoryServices.AccountManagement

but unfortunately as result I get an empty string

 

If you have one alternative solution to query the Active Directory please let me know

 

 

thank you in advance,

best regards,

Paco

post-53242-0-03240400-1424340801_thumb.j

Link to comment
  • 3 weeks later...

Final solution was to do a dll with the below VB code and call it by labview.

original code I found on neophob.com

 Dim adoLDAPCon, _
 adoLDAPRS, _
 strLDAP
 
 Public Function GetEmail(strAccountName As String, strDomainName As String) As String
 Set adoLDAPCon = CreateObject("ADODB.Connection")
 adoLDAPCon.Provider = "ADsDSOObject"
 adoLDAPCon.Open "ADSI"
 strLDAP = "'LDAP://" & strDomainName & "'"
 Set adoLDAPRS = adoLDAPCon.Execute("select mail from " & strLDAP & " WHERE objectClass = 'user'" & " And samAccountName = '" & strAccountName & "'")
 With adoLDAPRS
 If Not .EOF Then
 GetEmail = .Fields("mail")
 Else
 GetEmail = ""
 End If
 End With
 adoLDAPRS.Close
 Set adoLDAPRS = Nothing
 Set adoLDAPCon = Nothing
 End Function
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.