Solved

LDAP ADSI Active Directory - Efficiently get CN from UserName

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

832 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