473,383 Members | 1,885 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Finding a user in Active Directory

'***********************************************
Dim MySearcher As New
DirectorySearcher("LDAP://CN=Users,DC=corporate,DC=domainname,DC=com")

' Create a DirectorySearcher object.
Dim resEnt As SearchResult = MySearcher.FindOne()

'Now what? None of the examples are getting what I need

'***********************************************

I am a newbie and am simply trying to figure out how to query Active
Directory to see if a username being created on the Windows Form already
exists.

I feel like I am really close, but just can't get it.

(p.s. Although I am on A Windows Form, I have added the System.Web &
System.DirectoryServices references)

Thank you very much!

Environment:
Visual Studio 2005
Windows 2003 Mixed-Mode
Dec 7 '05 #1
2 1308
Okay, I have gotten to the point where I can display the Active Directory
path, but still can't find how to just display the username.

For Each mySearchResult As SearchResult In mySearchResultColl
MsgBox(mySearchResult.Path.ToString) 'not what I am looking for,
but very cool. This outlines the LDAP Path!!!
Next

"NathanC" wrote:
'***********************************************
Dim MySearcher As New
DirectorySearcher("LDAP://CN=Users,DC=corporate,DC=domainname,DC=com")

' Create a DirectorySearcher object.
Dim resEnt As SearchResult = MySearcher.FindOne()

'Now what? None of the examples are getting what I need

'***********************************************

I am a newbie and am simply trying to figure out how to query Active
Directory to see if a username being created on the Windows Form already
exists.

I feel like I am really close, but just can't get it.

(p.s. Although I am on A Windows Form, I have added the System.Web &
System.DirectoryServices references)

Thank you very much!

Environment:
Visual Studio 2005
Windows 2003 Mixed-Mode

Dec 7 '05 #2
Nathan,

Here is something that should get you on your way, note that this is
..net 2003 code

'strcon is your domain, strid is what to connect to the
domain as, and strpwd is strid's domain pwd
Dim Root As DirectoryEntry = New DirectoryEntry(strcon,
strID, strPWD)
Dim ds As System.DirectoryServices.DirectorySearcher(root)
Dim searchresult As DirectoryServices.SearchResult

'check to see if username exists in AD
ds = New DirectoryServices.DirectorySearcher

'strUserName is the username you are trying to create
ds.Filter = String.Format("(SAMAccountName={0})",
strUserName)

'this is common name for example it will return something
like cn=Doe,John if something is found
ds.PropertiesToLoad.Add("cn")

'In version 1.1 of the .Net framwork there was a memory
leak with ds.findone, might be fixed in .net 2.0
searchresult = ds.Findall()

If Len(searchresult.Properties.Item("cn")) = 0 Then
'username not found
'probably not the most efficient wat to see if
something is returned.
else
'username found
end if
That should get you on your way. If you need more let me know.

Dec 9 '05 #3

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

Similar topics

4
by: Mike | last post by:
Greetings, I am writing an Intranet application in ASP.NET using VB.NET. I am obtaining the username of the user with: uName = User.Identity.Name, which is in the form of DOMAIN\username. I...
4
by: ASGMikeG | last post by:
Hi, How do I find the user object for the current user in Active Directory i.e. the user running my program ? Regards Michael
6
by: Leo_Surf | last post by:
Hello, I need your help adding user in Active Directory from ASP.net website. Could any one provide me the complete code for the html page. As this is my curriculam project and I dont have any...
1
by: | last post by:
Hello, I'm keping myself busy here by investigating the world of LDAP and Active Directory. I have an application which allows users from the system to be selected from a list box and as a...
0
by: jakobsgaard | last post by:
It is possible to Map a certificate to a Active Directory User Account from DotNet? Please provide an example. Best regards, Ejnar Jakobsgaard...
9
by: Laurent Bugnion | last post by:
Hi, I am wondering what is the best way to find out which ASP.NET sessions are still active. Here is the reason: I have a custom control which can upload files. It saves the files in a folder...
8
by: kyosohma | last post by:
Hi, I am trying to query our domain to get a list of our users profile locations. I thought I might be able to use WMI, but I can't get it to work. I am using a Windows XP Pro workstation and...
7
by: Vio | last post by:
Hello everyone, i currently a beginner in php. I want to ask about Win2003 Active Directory users. Is it possible to retrieve Win2003 AD (just username & password) with php. I'm currenty...
4
by: Spam Catcher | last post by:
Hello All, I need to integrate my application into Active Directory. My application has the concept of groups, users, and also individual permissions. Users can be part of a group such as...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.