473,468 Members | 1,323 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Accessing LDAP with VB.

Hi,

I am trying to get someones email address out of the win 2003 server
Directory using there logon name and the following code.

Dim DSEntry As New System.DirectoryServices.DirectoryEntry("LDAP:" &
System.Environment.GetEnvironmentVariable("LOGONSE RVER") & "/CN=" &
System.Enviroment.Username & ",CN=Users,DC=laxeypartners,DC=com")
EmailAddress = DSEntry.Properties("mail").Value.ToString()

However, for some users the directory display name is not the same as the
logon name. e.g. Directory name is John Smith and logon name is
John.Smith.

When I use the logon name in the above code it does not find an entry in the
directory.

Does anyone know of a method that i can use to extract the default email
address from the logon name.

Many thanks,

Steve Lloyd
Nov 20 '05 #1
3 7151
Something like this should work

Private Function GetEmailAddress() As String
Dim Root As New DirectoryEntry("LDAP://RootDSE")
Dim DomainNC As String = Root.Properties("defaultNamingContext").Value
Root = New DirectoryEntry("LDAP://" & DomainNC)
Dim Searcher As New DirectorySearcher(Root)
With Searcher
.Filter = "(sAMAccountName=" & Environment.UserName & ")"
.SearchScope = SearchScope.Subtree
.PropertiesToLoad.Add("mail")
End With
Dim Result As SearchResult = Searcher.FindOne
Dim EMailAddress As String
If Not Result Is Nothing Then
EMailAddress = Result.GetDirectoryEntry.Properties("mail").Value
End If
Return EMailAddress
End Function

"Steve Lloyd" <Re*************@laxeyRemovepartners.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,

I am trying to get someones email address out of the win 2003 server
Directory using there logon name and the following code.

Dim DSEntry As New System.DirectoryServices.DirectoryEntry("LDAP:" &
System.Environment.GetEnvironmentVariable("LOGONSE RVER") & "/CN=" &
System.Enviroment.Username & ",CN=Users,DC=laxeypartners,DC=com")
EmailAddress = DSEntry.Properties("mail").Value.ToString()

However, for some users the directory display name is not the same as the
logon name. e.g. Directory name is John Smith and logon name is
John.Smith.

When I use the logon name in the above code it does not find an entry in
the
directory.

Does anyone know of a method that i can use to extract the default email
address from the logon name.

Many thanks,

Steve Lloyd

Nov 20 '05 #2
Perfect, thank you very much...
"Jared" <VB***********@email.com> wrote in message
news:10*************@corp.supernews.com...
Something like this should work

Private Function GetEmailAddress() As String
Dim Root As New DirectoryEntry("LDAP://RootDSE")
Dim DomainNC As String = Root.Properties("defaultNamingContext").Value
Root = New DirectoryEntry("LDAP://" & DomainNC)
Dim Searcher As New DirectorySearcher(Root)
With Searcher
.Filter = "(sAMAccountName=" & Environment.UserName & ")"
.SearchScope = SearchScope.Subtree
.PropertiesToLoad.Add("mail")
End With
Dim Result As SearchResult = Searcher.FindOne
Dim EMailAddress As String
If Not Result Is Nothing Then
EMailAddress = Result.GetDirectoryEntry.Properties("mail").Value
End If
Return EMailAddress
End Function

"Steve Lloyd" <Re*************@laxeyRemovepartners.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,

I am trying to get someones email address out of the win 2003 server
Directory using there logon name and the following code.

Dim DSEntry As New System.DirectoryServices.DirectoryEntry("LDAP:" &
System.Environment.GetEnvironmentVariable("LOGONSE RVER") & "/CN=" &
System.Enviroment.Username & ",CN=Users,DC=laxeypartners,DC=com")
EmailAddress = DSEntry.Properties("mail").Value.ToString()

However, for some users the directory display name is not the same as the logon name. e.g. Directory name is John Smith and logon name is
John.Smith.

When I use the logon name in the above code it does not find an entry in
the
directory.

Does anyone know of a method that i can use to extract the default email
address from the logon name.

Many thanks,

Steve Lloyd


Nov 20 '05 #3
You're welcome

"Steve Lloyd" <Re*************@laxeyRemovepartners.com> wrote in message
news:uE****************@TK2MSFTNGP09.phx.gbl...
Perfect, thank you very much...
"Jared" <VB***********@email.com> wrote in message
news:10*************@corp.supernews.com...
Something like this should work

Private Function GetEmailAddress() As String
Dim Root As New DirectoryEntry("LDAP://RootDSE")
Dim DomainNC As String =
Root.Properties("defaultNamingContext").Value
Root = New DirectoryEntry("LDAP://" & DomainNC)
Dim Searcher As New DirectorySearcher(Root)
With Searcher
.Filter = "(sAMAccountName=" & Environment.UserName & ")"
.SearchScope = SearchScope.Subtree
.PropertiesToLoad.Add("mail")
End With
Dim Result As SearchResult = Searcher.FindOne
Dim EMailAddress As String
If Not Result Is Nothing Then
EMailAddress = Result.GetDirectoryEntry.Properties("mail").Value
End If
Return EMailAddress
End Function

"Steve Lloyd" <Re*************@laxeyRemovepartners.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
> Hi,
>
> I am trying to get someones email address out of the win 2003 server
> Directory using there logon name and the following code.
>
> Dim DSEntry As New System.DirectoryServices.DirectoryEntry("LDAP:" &
> System.Environment.GetEnvironmentVariable("LOGONSE RVER") & "/CN=" &
> System.Enviroment.Username & ",CN=Users,DC=laxeypartners,DC=com")
> EmailAddress = DSEntry.Properties("mail").Value.ToString()
>
> However, for some users the directory display name is not the same as the > logon name. e.g. Directory name is John Smith and logon name is
> John.Smith.
>
> When I use the logon name in the above code it does not find an entry
> in
> the
> directory.
>
> Does anyone know of a method that i can use to extract the default
> email
> address from the logon name.
>
> Many thanks,
>
> Steve Lloyd
>
>



Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: mel finney | last post by:
Hi I am trying to access a LDAP server with ASP with no sucess. I can do it with ColdFusion but not ASP. All the examples I have seen so far do not use passwords or userid's. My LDAP server...
1
by: MarkAurit | last post by:
The below works when the first parameter to DirectoryEntry is set to our corporate AD domain, such as LDAP://FORD. But if I try for a group within the domain, such as LDAP://FORD/TRUCKS, I get the...
1
by: Jody Gelowitz | last post by:
This one should be relatively simple, though I have yet to figure it out. I have an ASP.NET project which uses LDAP authentication to login to the system. When run on our Development or Staging...
2
by: Serline | last post by:
I can login to the domain hosted by Win 2003. However when my .NET application trys to authenticate using NTLM with LDAP on Win 2003, I'm encountering problems. It's showing "The authentication...
1
by: Pixaar | last post by:
hello.. I am new to VB and really new to LDAP I am trying to write an application for our lunch card system...where a student's card is read by a barcode reader and the information (a string)...
1
by: Rohit Ambani | last post by:
I have created Login.aspx Page On Click of Login Button.I invoke the code as follows ====================================================== Dim adPath As String = "LDAP://172.21.1.19" 'Path to your...
2
by: sweetpotatop | last post by:
Hi, I have an asp.net applicaiton in which I want to control the accessibility. Does anyone has any idea how I can access the Lotus Notes address book through LDAP? That way, I can restrict...
3
by: TomikZ | last post by:
I'd like to get some user account properties using .asp script. When I try to use ADSI WINNT provider it works fine except that I apparently cannot access some properties such as...
0
by: Sells, Fred | last post by:
I'm running python 2.5 (or 2.4) in an XP environment. I downloaded and installed the .dll's from OpenLDAP-2.4.8+OpenSSL-0.9.8g-Win32.zip and copied the .dll's in c:/windows/system32 as instructed...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.