Solved

LDAP ADSI Active Directory - Efficiently get CN from UserName

Posted on 2003-10-30
4
2,060 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
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 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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

626 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