Pablo, here is some code I use in VB.NET to do a similar thing, should be convertable to C# without much hassle
strUserName = the fully qualified LDAP path of a user or group, ie LDAP://CN=GroupName,DC=testdomain,DC=local 'Constants required, rest are in the online doco for NameTranslate Const ADS_NAME_INITTYPE_GC = 3 Const ADS_NAME_TYPE_1779 = 1 Const ADS_NAME_TYPE_NT4 = 3 Dim Translate As New ActiveDs.NameTranslate Dim strUser As String 'We want to chat to a GC server, any one will do Translate.Init(ADS_NAME_INITTYPE_GC, "") 'Pass in the FQDN name of the object Translate.Set(ADS_NAME_TYPE_1779, Mid(strUserName, 8)) <-- the call doesnt like the LDAP:// on the front, so strip it 'Get back the NT v4 Equivalent strUser = Translate.Get(ADS_NAME_TYPE_NT4) Translate = Nothing strUser now = the DOMAIN\UserName pair You can easily go the other way, ie pass in the Domain\username pair, and get back the LDAP path. Its all in the online doco, just do a search for NameTranslate Very cool actually, was hacking around trying to pull apart LDAP strings and massage them myself, this is MUCH easier (and faster) HTH Glenn (lucky you asked today, worked out how to to this last night *grin*) ----- Original Message ----- From: "Pablo Curello" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, August 05, 2003 9:44 PM Subject: RE: [ActiveDir] Connection String That's right, but what if the user Pablo Curello is inside an organizational group ? In that case, the LDAP string should be (for example): "LDAP://cn=Pablo Curello, ou=Sales, dc=yourdomain, dc=com". It doesn�t work with: "LDAP://cn=Pablo Curello, dc=yourdomain, dc=com" Thanks. -----Original Message----- From: Costanzo, Ray [mailto:[EMAIL PROTECTED] Sent: Monday, August 04, 2003 2:34 PM To: [EMAIL PROTECTED] I believe that you mean DOMAIN\Username, and if so: Function GetFullName(sUser) Dim sUsername, sDomain sUserInfo = Split(sUser, "\") sDomain = sUserInfo(0) sUsername = sUserInfo(1) Set oUser = GetObject("WinNT://" & sDomain & "/" & sUsername & ",user") GetFullName = oUser.Fullname Set oUser = Nothing End Function That will give you the full name, such as: "Curello\, Pablo" And then you can use: sFullname = GetFullName("pcurello") sLDAP = "LDAP://cn=" & sFullname & ",dc=yourdomain,dc=com" How you get the dc= part from the oldschool netbios name, I'm not sure though. And I can't translate this to C for you. :] Ray at work -----Original Message----- From: Pablo Curello [mailto:[EMAIL PROTECTED] Hello all. Does anybody know how to transform a user's identity "DOMAIN/USERNAME" to an ldap connection string "CN=name, DC=..." ? I know how to do it in COM (C++) using IADsNameTranslate interface, but now I�m using C#. Thanks. **************************************************************************** ****************************** The information contained in this e-mail message is intended only for the personal and confidential use of the recipient(s) named above. Distribution, publication, or retransmission of this message is strictly prohibited. This message may be a bank to client communication and as such is priviliged and confidential. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this document in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail, and delete the original message. The sender of this e-mail specifically "opts-out" of the Electronic Signatures and Global and National Commerce Act (E-Sign) and any and all similar state and federal acts. Accordingly, but without limitation, any and all documents, contracts, and ageements must contain a handwritten signature of the sender to be legal, valid, and enforceable. **************************************************************************** ****************************** List info : http://www.activedir.org/mail_list.htm List FAQ : http://www.activedir.org/list_faq.htm List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/ List info : http://www.activedir.org/mail_list.htm List FAQ : http://www.activedir.org/list_faq.htm List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/ List info : http://www.activedir.org/mail_list.htm List FAQ : http://www.activedir.org/list_faq.htm List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/
