| Re: Using NameTranslate object. -
06-04-2007, 09:45 AM
"Rowland" <EMAIL REMOVED> wrote in message
news:cffurq$2vs$EMAIL REMOVED...
> Hi,
>
> I'm not sure if this is an active directory issue, or a VB issue. I've got
> some code to convert an NT login name to a Distinguished Name so I can
query
> an Active Directory server. Unfortunately, it always returns an empty
string
> instead of the distinguished name.
> I'm using VB 6 and Windows 2003 Server as a test server. Querying the AD
> server with the distinguished name works correctly.
>
> Anyhoo, here's the code:
> -------------------------------------------
> Dim strNetBIOSDomain As String
> Dim oTrans As New NameTranslate
>
> oTrans.Init 3, ""
> oTrans.Set 3, LoginName 'LoginName is a string.
> strNetBIOSDomain = oTrans.Get(3)
>
> MsgBox strNetBIOSDomain + vbCrLf + CStr(Len(strNetBIOSDomain))
> -------------------------------------------
>
> The output of this is a msgbox if I use a correct login name (e.g.
> administrator):
> ___________
> | Title |
> |___________|
> | |
> | 0 |
> ---------------
>
> or an error message saying "Could not find name" if I use an incorrect
login
> name (e.g. administtttttrator )
>
> Thanks in advance,
>
> Rowland.
>
> Has anybody got any clues as to why this happens?
>
I've now fixed the problem although it had stumped me for the whole day! It
seems I just had to prefix the server name onto the login name. HOWEVER - If
anyone knows a way to get the name of the AD server automatically, I would
really appreciate it though, as skinner_ad is just a test environment.
New code:
Public Function fNT2AD(LoginName As String)
'There is one hard-coded parameter here - "skinner_ad\" - It is the name of
the server.
Dim strNetBIOSDomain As String
Dim oTrans As New NameTranslate
oTrans.Init 3, ""
oTrans.Set 3, "skinner_ad\" & LoginName
strNetBIOSDomain = oTrans.Get(1)
fNT2AD = strNetBIOSDomain
End Function
Rowland. |