' Listing 2: The dn Function Function dn(ntid) Dim objrootdse, strdnsdomain, objtrans, strnetbiosdomain Dim struserdn, objuser ' Declare the constants for ADSI's NameTranslate object. Const ADS_NAME_INITTYPE_DOMAIN = 1 Const ADS_NAME_TYPE_NT4 = 3 Const ADS_NAME_TYPE_1179 = 1 ' Determine the DNS domain name from the RootDSE object. Set objrootdse = GetObject("LDAP://RootDSE") strdnsdomain = objrootdse.Get("DefaultNamingContext") ' Create the NameTranslate object, then use it to obtain the ' NetBIOS domain name from the DNS domain name. Set objtrans = CreateObject("NameTranslate") objtrans.init ADS_NAME_TYPE_NT4, strdnsdomain objtrans.set ADS_NAME_TYPE_1179, strdnsdomain strnetbiosdomain = objtrans.Get(ADS_NAME_TYPE_NT4) ' Remove the backslash. strnetbiosdomain = Left(strnetbiosdomain, Len(strnetbiosdomain)-1) ' Use the NameTranslate object to convert the NT ID to the DN for the LDAP provider. objtrans.init ADS_NAME_INITTYPE_DOMAIN, strnetbiosdomain objtrans.set ADS_NAME_TYPE_NT4, strnetbiosdomain & "\" & ntid struserdn=objtrans.Get(ADS_NAME_TYPE_1179) Set objUser = GetObject("LDAP://" & strUserDN) dn = objuser.distinguishedname End Function