Richard
Tue Jul 08 11:15:56 CDT 2003
"Richard Mueller [MVP]" <rlmueller@ameritech.net> wrote in message
news:eJOYGrVRDHA.704@tk2msftngp13.phx.gbl...
> barabba wrote:
>
> > Hi folks,
> >
> > I need to determine the distinguised name of the current domain.
> > I am familiar with the code to produce the default naming context, but
> > how do I get the distinguished name ?
> >
> > Using the same code and replacing "DefaultNamingContext" with
> > "DistinguishedName" generates an error that says the property cache
> > could not be loaded (sorry I don't have the code at hand).
>
> Hi,
>
> It sounds like you are using the RootDSE object. If so, then the
> "defaultNamingContext" is the Distinguished Name of the current domain,
the
> domain that the current user has authenticated to. You can bind to the
> domain with "defaultNamingContext". For example:
>
> Set objRootDSE = GetObject("LDAP://RootDSE")
> strDNSDomain = objRoot.Get("defaultNamingContext")
> Set objDomain = GetObject("LDAP://" & strDNSDomain)
> Wscript.Echo "defaultNamingContext: " & strDNSDomain
> Wscript.Echo "DN of domain: " & objDomain.distinguishedName
>
> If you were to retrieve "rootDomainNamingContext" from the RootDSE object,
> you would get the DN of the root domain of the forest. Once you have bound
> to the domain object, you can retrieve other "name" attributes, like "dn"
> (the relative distinguished name), or "AdsPath".
>
> --
> Richard
> Microsoft MVP Scripting and ADSI
> HilltopLab web site -
http://www.rlmueller.net
> --
>
>
Hi,
I just noticed I wrote "dn" in the last sentence of my post when I should
have written "dc". "dn" is the abbreviation for Distinguished Name, "dc" is
the abbreviation for Domain Component. The relative distinguished name (RDN)
of a domain is the highest level domain component name. For example, if the
Distinguished Name (DN) of the domain is "dc=MyDomain,dc=MyCompany,dc=com",
then the "dc" attribute will be "MyDomain". Note that there is another name
for domains, sometimes called the NetBIOS domain name, or the NT name. In my
example, the NetBIOS domain name would usually be "MyDomain". However, it
could be something completely different. The NetBIOS domain name could be
"Surprise". You would bind to the domain using the WinNT provider with the
NetBIOS domain name.
If the client is W2k or above, you can get the NetBIOS domain name of the
current domain from the ADSystemInfo object, as explained by Dan Morgan in
his post. You can also use the WshShell object to get this from the
environment variable USERDOMAIN, but only if the client is NT or above. On
any client you can use the NameTranslate object to convert the DN of the
domain (retrieved from the RootDSE object) to the NetBIOS domain name. For
example:
' Determine DNS domain name from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
' Use the NameTranslate object to find the NetBIOS domain name from the
' DNS domain name.
Set objTrans = CreateObject("NameTranslate")
objTrans.Init 3, strDNSDomain
objTrans.Set 1, strDNSDomain
strNetBIOSDomain = objTrans.Get(3)
' Remove trailing backslash.
strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1)
--
Richard
Microsoft MVP Scripting and ADSI
HilltopLab web site -
http://www.rlmueller.net
--