Solved

LDAP ADSI Active Directory - Efficiently get CN from UserName

Posted on 2003-10-30
4
2,019 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
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…

911 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

17 Experts available now in Live!

Get 1:1 Help Now