473,807 Members | 2,877 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Code Check: Active Directory

Hi all,

I have some code which I cobbled together from some examples online, so its
probably wrong, although I did have it working a little while ago,
unfortunately for some reason it seems to have stopped working..nothin g's
change infrastructure wise, the only thing that has changed is that my
project has been converted to VS2005 - I'm not suggesting this has caused a
problem - just stating its the only change (that I can remember!)...

The code (snipped from the class):

Public Sub Search(ByVal samaccountname As String, ByVal activeDirectory As
String)

' declare variables
Dim DirectoryEntry As DirectoryEntry = New
DirectoryEntry( LDAP://myActiveDirecto ry)
Dim DirectorySearch er As DirectorySearch er = New
DirectorySearch er(DirectoryEnt ry)
Dim Results As DirectoryServic es.SearchResult Collection
Dim Result As DirectoryServic es.SearchResult
Dim ResultPropertyC ollection As ResultPropertyC ollection
Dim ResultProperty As String

' define search properties
With (DirectorySearc her)
.Filter =
"(&(objectClass =User)(objectCa tegory=User)(sa maccountname=" & samaccountname
& "))"
.SearchScope = SearchScope.Sub tree
End With

' search
Results = DirectorySearch er.FindAll

' check number of results
If Results.Count > 0 Then

' iterate through results
For Each Result In Results

' exception handling
Try

' populate collection
ResultPropertyC ollection = Result.Properti es

' set class variables
Me.SetRawData(R awData)

' exception handling
Try

Me.SetGivenName (Result.Propert ies("givenname" ).Item(0).ToStr ing)

Catch ex As System.NullRefe renceException

Me.SetGivenName ("")

End Try

' exception handling
Try

Me.SetSurname(R esult.Propertie s("sn").Item(0) .ToString)

Catch ex As System.NullRefe renceException

Me.SetSurname(" ")

End Try

End If

End Sub
This is a cut down version of what I'm currently using, but only in that I
was pulling more properties out..

Can anyone spot anything which would prevent the search from working? I'm
not getting any errors, but equally I'm not getting any values out of the ad
either - really frustrating as I was dead impressed with myself when I had
it working originally! :o)

Also, I'm sure this is nothing to do with it but are there any specific
ports that would need to be open on a LAN to enable this? I'd imagine I'd
have received an error somewhere if so - and I'm pretty sure that there
haven't been any infrastructure changes since it was working..

Regards

Rob
Nov 19 '05 #1
3 1316
Oh, I should add, it seems to be that where I test for the results > 0 - it
never is, its always 0....but as I mentioned, no error?
Nov 19 '05 #2
Update:

I just ran my old .exe written in .net 1.1 and it fires up and searches
without any problems at all? Anyone got any ideas - it appears to only be a
problem because of .net 2.0

Regards

Rob
Nov 19 '05 #3
Fixed it!
Nov 19 '05 #4

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

Similar topics

1
4017
by: Daveyk0 | last post by:
Hello there, I have a front end database that I have recently made very many changes to to allow off-line use. I keep copies of the databases on my hard drive and link to them rather than the live databases on the network. Is there a way, via code, when I get back in-house from being on the road to click a button, and select the backends I want to link to? I would want to delete all the current links and link to the "live"
3
3490
by: Luis Esteban Valencia | last post by:
Hello gusys, Is it possible to make my asp.net application add users to the AD , I also want to be able to delete users, modify their information, everything through a website. Thanks for the info
4
1392
by: Patirck Ige | last post by:
Would it be easier to have an intranetsystem built based on some security gruopson Active directory or having to use a Database to have a validation store and Roles. Which way would be the best to go?
3
2655
by: Adrian Parker | last post by:
At the moment, we have a simple user id / password entry screen to login to our website, the data credentials are held in our database. We've now been asked to integrate with active directory so that users on the lan who are already logged in via active directory no longer need to log into the website, but automatically are logged in using their network userid (which should match the old website login). I can see how I could prompt for...
10
4072
by: Hriday | last post by:
Hi there, Please help me..It is urgent This is Hriday, working on windows authentication with Active Directory... My requirment is when a user sends a request to my web Applicatoin I want to Pop up windows Authentication box so that user will give his userId, Password & domain name for authenticaion. After that I want to take these three info of user and make a search in Active Directory.
3
11317
by: Lucky | last post by:
Hi guys, after long long time. i'm back again with another problem. this time i think the problem is very very interesting and i really need you help on this. i'm trying to connect to the Active Directory. for that i've added one linked server to connect to the active directory. and then query like this: adding linked server:
2
5992
by: Jim in Arizona | last post by:
My goal, somehow, is to populate a dropdownlist with all the user names in active directory. I don't even know where to begin, really. I added a reference to System.DirectoryServices so I could use the System.DirectoryServices.ActiveDirectory namespace. I don't even know if this is the right way to go as I can't seem to find anything in that namespace that would help me query active directory for names. I can't use an LDAP query...
3
1554
by: Pedro | last post by:
Hi all, I would like to know, how can I check the name of the current user that is Log on in O.S XP. Hi already try the Environment.UserName.ToString(); but is not what i would like to appear,its abreviated, like 'MJhonson', and and what i want is the complete name 'Michael Johnson'.
2
2765
by: rote | last post by:
My sceanrio is this on an asp.net 2.0 freamework. I want to use any of the data controls e.g Gridview,DetailView etc.. But i want some buttons e.g update,edit save etc to be enable or disabled based on if they belong to some security groups in active directory. I'm looking for the best options for this because i want to store those security groups somewhere and then check for the user against those security groups for their authorisation...
1
4887
by: chennaibala | last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading. i develop program,which can upload many file in folder.problem is,am unable to save my file name in to database.because i used same name for all input file type as file. i dont know get name of file.below i presented my coding for ur view.fed up with my coding..pls...
0
9720
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9599
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10626
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10374
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9193
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7650
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5546
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5685
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4330
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.