Using NameTranslate object.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rowland

    Using NameTranslate object.

    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 strNetBIOSDomai n As String
    Dim oTrans As New NameTranslate

    oTrans.Init 3, ""
    oTrans.Set 3, LoginName 'LoginName is a string.
    strNetBIOSDomai n = oTrans.Get(3)

    MsgBox strNetBIOSDomai n + vbCrLf + CStr(Len(strNet BIOSDomain))
    -------------------------------------------

    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. administtttttra tor )

    Thanks in advance,

    Rowland.

    Has anybody got any clues as to why this happens?


  • Rowland

    #2
    Re: Using NameTranslate object.


    "Rowland" <banksr0@hotmai l.com> wrote in message
    news:cffurq$2vs $1@titan.btinte rnet.com...[color=blue]
    > 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[/color]
    query[color=blue]
    > an Active Directory server. Unfortunately, it always returns an empty[/color]
    string[color=blue]
    > 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 strNetBIOSDomai n As String
    > Dim oTrans As New NameTranslate
    >
    > oTrans.Init 3, ""
    > oTrans.Set 3, LoginName 'LoginName is a string.
    > strNetBIOSDomai n = oTrans.Get(3)
    >
    > MsgBox strNetBIOSDomai n + vbCrLf + CStr(Len(strNet BIOSDomain))
    > -------------------------------------------
    >
    > 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[/color]
    login[color=blue]
    > name (e.g. administtttttra tor )
    >
    > Thanks in advance,
    >
    > Rowland.
    >
    > Has anybody got any clues as to why this happens?
    >[/color]

    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(LoginNam e As String)
    'There is one hard-coded parameter here - "skinner_ad \" - It is the name of
    the server.
    Dim strNetBIOSDomai n As String
    Dim oTrans As New NameTranslate
    oTrans.Init 3, ""
    oTrans.Set 3, "skinner_ad \" & LoginName
    strNetBIOSDomai n = oTrans.Get(1)
    fNT2AD = strNetBIOSDomai n
    End Function

    Rowland.


    Comment

    Working...