How can I obtain the longer computer name of a computer via vbscript?
All techniques I've seen so far only return the NetBIOS name, which is
15 characters max. Windows has supported computer names up to 63
characters long since at least Windows 2000. Most computers on my
network have computer names longer than 15 characters.

Thanks.

Brent Gardner
Network Administrator
IPRO Tech, Inc.

Re: How to obtain computer name longer than 15 characters? by Richard

Richard
Wed Dec 13 22:35:23 CST 2006

Brent Gardner wrote:

> How can I obtain the longer computer name of a computer via vbscript? All
> techniques I've seen so far only return the NetBIOS name, which is 15
> characters max. Windows has supported computer names up to 63 characters
> long since at least Windows 2000. Most computers on my network have
> computer names longer than 15 characters.

You want the Common Name of the object, the value of the cn attribute. For
example, to retrieve the Common Name of the current computer:
=========
Set objSysInfo = GetObject("ADSystemInfo")
strComputerDN = objSysInfo.ComputerName
Set objComputer = GetObject("LDAP://" & strComputerDN)
Wscript.Echo objComputer.cn

Does this help?

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net



Re: How to obtain computer name longer than 15 characters? by Brent

Brent
Thu Dec 14 09:56:35 CST 2006

Richard-

Thanks for your reply.

I had to change GetObject("ADSystemInfo") to
CreateObject("ADSystemInfo") to get the code to run, and then
unfortunately it still returned only 15 characters.

Brent


Richard Mueller wrote:
> Brent Gardner wrote:
>
>> How can I obtain the longer computer name of a computer via vbscript? All
>> techniques I've seen so far only return the NetBIOS name, which is 15
>> characters max. Windows has supported computer names up to 63 characters
>> long since at least Windows 2000. Most computers on my network have
>> computer names longer than 15 characters.
>
> You want the Common Name of the object, the value of the cn attribute. For
> example, to retrieve the Common Name of the current computer:
> =========
> Set objSysInfo = GetObject("ADSystemInfo")
> strComputerDN = objSysInfo.ComputerName
> Set objComputer = GetObject("LDAP://" & strComputerDN)
> Wscript.Echo objComputer.cn
>
> Does this help?
>

Re: How to obtain computer name longer than 15 characters? by Brent

Brent
Thu Dec 14 11:14:49 CST 2006

Richard's reply led me to more fruitful research. Here's the code that
gets me what I wanted:

Set objSysInfo = CreateObject("ADSystemInfo")
strComputerDN = objSysInfo.ComputerName
Set objComputer = GetObject("LDAP://" & strComputerDN)
strFullDNSName = objComputer.dnsHostName
strHostNameOnly = left(strFullDNSName, instr(strFullDNSName, ".") - 1)
Wscript.Echo strHostNameOnly

Thanks again, list.


Brent Gardner wrote:
> Richard-
>
> Thanks for your reply.
>
> I had to change GetObject("ADSystemInfo") to
> CreateObject("ADSystemInfo") to get the code to run, and then
> unfortunately it still returned only 15 characters.
>
> Brent
>
>
> Richard Mueller wrote:
>> Brent Gardner wrote:
>>
>>> How can I obtain the longer computer name of a computer via vbscript?
>>> All techniques I've seen so far only return the NetBIOS name, which
>>> is 15 characters max. Windows has supported computer names up to 63
>>> characters long since at least Windows 2000. Most computers on my
>>> network have computer names longer than 15 characters.
>>
>> You want the Common Name of the object, the value of the cn attribute.
>> For example, to retrieve the Common Name of the current computer:
>> =========
>> Set objSysInfo = GetObject("ADSystemInfo")
>> strComputerDN = objSysInfo.ComputerName
>> Set objComputer = GetObject("LDAP://" & strComputerDN)
>> Wscript.Echo objComputer.cn
>>
>> Does this help?
>>