Solved

LDAP ADSI Active Directory - Efficiently get CN from UserName

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
link access with Quickbooks 9 74
mixing C++ & C# in Vis Studio 2013 7 281
windbg taking it's time 32 108
What .NET URL re-routing tool did I use? 2 93
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.  …
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…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

752 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