Solved

LDAP ADSI Active Directory - Efficiently get CN from UserName

Posted on 2003-10-30
4
2,014 Views
Last Modified: 2013-12-03
Ok, I have been trying to figure this out all week.

I'm using Visual Basic 6 with the ADSI interface to access Active Directory.  We have made our own schema extension to AD to include a 'balance' attribute to the user.  We have a database with UserName, Balance and FullName in a table.  What i need is an efficient way to write the balance from the database to the AD.  

Heres what i've got:

Set iadsOpenDS = GetObject("LDAP:")

Set iadsUser = iadsOpenDS.OpenDSObject("LDAP://PDCName/CN=UserName,CN=Users," & g_uSetup.sLDAPDomainPath, g_uSetup.sLDAPUserName, g_uSetup.sLDAPPassword, ADS_FAST_BIND)

sBalanceInfo = FormatCurrency(rsUser("Balance"), -1, vbTrue, vbFalse) & " on " & FormatDateTime(Now(), vbShortDate) & " " & Format(Now(), "Medium Time")
iadsUser.Put "Balance", sBalanceInfo
iadsUser.SetInfo

Ok, so the problem is, I have the user's UserName (ie. the name they could use to log on to the box with) but I need their LDAP CN name so that i can bind to their object.

One way could be to search the AD from the OpenDSObject call, if this is possible?  I have not seen any examples of this and tried and failed to do it with a search filter. (sAMAccountName is the same as UserName in AD)  

Something like:

Set iadsUser = iadsOpenDS.OpenDSObject("LDAP://PDCName/sAMAccountName=" & rsUser("UserNameBase").Value & ",CN=Users," & g_uSetup.sLDAPDomainPath, g_uSetup.sLDAPUserName, g_uSetup.sLDAPPassword, 0)

The reason I want to use the OpenDSObject is because ADS_FAST_BIND is very quick.

Or is there some kind of function I can call to quickly retrieve the user's CN?  Remembering that I may have to update 10,000 users at once.
0
Comment
Question by:Flamer
4 Comments
 
LVL 4

Accepted Solution

by:
Milind00 earned 250 total points
ID: 9678460
Most efficent way could be searching for all the users at a times using ADO query to retrivie "ADsPath" property.  And for each ADsPath you can bind using OpenDSObject.


More info on using ADSI ADO query:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netdir/adsi/modifying_an_adsi_object_from_ado.asp

Also there are lot of usefull srcipt here
http://www.rallenhome.com/books.html
0
 
LVL 6

Expert Comment

by:DominicCronin
ID: 9750690
Milind00's answer is correct
0
 
LVL 2

Author Comment

by:Flamer
ID: 10818583
Thanks for your help everyone.  Its been a while since i worked on this problem, unfortunately i never actually found a suitable solution.

Points awarded to Milind00.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now