PC Review


Reply
Thread Tools Rate Thread

Active Directory VB.NET

 
 
Adam J. O'Rourke
Guest
Posts: n/a
 
      19th Aug 2003
HI I'm trying to write a Vb program to get some pieces of information
for our Active directory, but when i connect to my AD server, the only
information i can seem to get is the DNS information. I wrote the
following code to try and find what search filters i needed to get the
User information i wanted, but all i get back is the DNS information,
any help you can give me would be a huge help.

Dim strpath As String =
"LDAP://server.domain.com/DC=domain,DC=com"
Dim LogonName As String = "anonymous"
Dim LogonPassword As String = ""
Dim count As Int16

StopSearch = False

Dim myDE As New
System.DirectoryServices.DirectoryEntry(strpath, LogonName,
LogonPassword)
myDE.AuthenticationType = AuthenticationTypes.ReadonlyServer


Dim MySearch As New
System.DirectoryServices.DirectorySearcher(myDE)

MySearch.SearchRoot = myDE
MySearch.SearchScope = SearchScope.Subtree
txtOutput.Text = ""

Dim results As SearchResultCollection
Try
results = MySearch.FindAll

Dim res As SearchResult
Dim key, objValue
count = 0
For Each res In results
If StopSearch Then Exit For
For Each key In res.Properties.PropertyNames
If StopSearch Then Exit For
If UCase(key) = "DC" Then txtOutput.Text &= vbCrLf
& vbCrLf
txtOutput.Text &= key & " = "
Try
For Each objValue In res.Properties(key)
If StopSearch Then Exit For
txtOutput.Text &= objValue.ToString() &
vbCrLf
Next objValue
Catch
End Try
System.Windows.Forms.Application.DoEvents()
count += 1
If count = 10 Then Exit For
Next
Next
Catch
MsgBox("invalid search")
Exit Sub
End Try
MsgBox("finished search")


This code shows me alot of information, but not the information i
want.

Thank you,
Adam J. O'Rourke
Programer/Technician
 
Reply With Quote
 
 
 
 
Marc Scheuner [MVP ADSI]
Guest
Posts: n/a
 
      20th Aug 2003
>HI I'm trying to write a Vb program to get some pieces of information
>for our Active directory,


Comments inline with code.....

Dim strpath As String = "LDAP://server.domain.com/DC=domain,DC=com"

Tip: try to use serverless binding unless you have specific reason to
use the server: LDAP://dc=domain,dc=com should be fine

BIG TIP: add a "using System.DirectoryServices" to your file, then you
don't need to keep repeating that all over the place!

>Dim LogonName As String = "anonymous"
>Dim LogonPassword As String = ""
>Dim myDE As New System.DirectoryServices.DirectoryEntry(strpath, LogonName, LogonPassword)


Tip: don't specify user name and password unless you really have to -
try using this instead

dim myDE as New DirectoryEntry(strpath)

>Dim MySearch As New DirectorySearcher(myDE)
> MySearch.SearchRoot = myDE


This is redundant - you've already specified "myDE" as your search
root by passing it in the constructor

YOu'll also need to specify something to search for - a filter. If you
want users, try something like this:

myDE.Filter = "(objectCategory=Person)"

That should help to get you started.

Also, you might want to subscribe to the microsoft.public.adsi.general
newsgroup - that's really where the AD / ADSI / LDAP mavens hang out!
:-)

Marc

================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
question on upgrading from active directory 2000 to active directory 2003 Gary M Microsoft Windows 2000 Active Directory 2 16th Mar 2007 07:57 PM
Active Directory, Active Directory Federation Services and Microsoft Integration Identiy Server Mas Libman [MSFT] Microsoft Windows 2000 Active Directory 0 6th May 2005 10:55 PM
[Active Directory] On what ground does LDAP connect to Active Directory RTT Microsoft VB .NET 0 12th Apr 2005 04:20 PM
Arguments for 2003 Active directory versus 2000 active directory? =?Utf-8?B?c3RlcGhlbmJiYWtlcg==?= Microsoft Windows 2000 Active Directory 4 23rd Dec 2003 04:40 AM
compatibility between W2K Active Directory and W2k3 Active Directory Dani Microsoft Windows 2000 Active Directory 1 15th Sep 2003 11:03 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:21 PM.