Finding a user in Active Directory

  • Thread starter Brian Denning via .NET 247
  • Start date
B

Brian Denning via .NET 247

I have a program that I have created (VB.NET 2003) that takes anexcel spread sheet and creates a user based on what is in theSS. This is working properly. Now, I want the be able to takeanother spreadsheet and update information of the users in thatsheet. Here is my code on how I initially create the user:

Dim myDirectoryEntry As DirectoryServices.DirectoryEntry
Dim myDE As DirectoryServices.DirectoryEntry
Dim myEntries As DirectoryServices.DirectoryEntries

RootDSE = RootDSE.Insert(7, mOU)

myDE = New DirectoryServices.DirectoryEntry(RootDSE)
myEntries = myDE.Children
myDirectoryEntry = myEntries.Add("CN=" & mUserName, "user")
myDirectoryEntry.Properties("samAccountName").Value = mUserName

... Do other properties here

myDirectoryEntry.CommitChanges()

Now, when I run the second spread sheet it looks to see if theusername already exists and if it does then it checks to see ifthe first and last names match. If they match then they aresupposed to update the rest of the fields. So assuming I have acomplete match, this is the code that I do:

'Same as others above
myDirectoryEntry = myEntries.Find("CN=" & mUserName)

I get an error that say that the object is not found on theserver. I know that it is there... I can not figure out thecorrect syntax for the life of me... help!

BTW this program is running on a W2K domain controller.

Thanks
 
M

Marc Scheuner [MVP ADSI]

Now, I want the be able to take another spreadsheet and update information of the users in that sheet.

Okay, how about using the WHOLE user's LDAP path for that?? E.g. since
you *KNOW* where you created *WHICH* user, you should be able to fill
in the full user LDAP path name, no? Something like "cn=John
Doe,dc=YourCompany,dc=com".

Then use that LDAP path (or distinguished Name = DN) for the user, and
just bind to the user - no need to do a .Find or other search
operation!
myDirectoryEntry = new DirectoryEntry("LDAP://" + <value from spreadsheet>);

THen do your stuff to the user entry, and commit changes. Done!

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top