• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 265
  • Last Modified:

Determining DNS Domain

How do I get the DNS Domain of the local PC with a VB Script?

For example, if my host is bob and my domain is foo.bar.com, how do I get the foo.bar.com?

I need this on a Windows 2000 PC...
0
rkogelhe
Asked:
rkogelhe
3 Solutions
 
rettiseertCommented:
?

Try this...

Dim WshNetwork

Set WshNetwork = WScript.CreateObject("WScript.Network")

MsgBox WshNetwork.UserDomain
0
 
PreeceCommented:
That should prob read:

Dim WshNetwork As Object

Set WshNetwork = CreateObject("WScript.Network")

MsgBox WshNetwork.UserDomain


; - )
0
 
rkogelheAuthor Commented:
Hmmm....

That seems to just display the first part of the domain.

It displays just "foo". Not "foo.bar.com". Note that "foo" is the same as the NT Domain as well, so I wonder if this script displays the NT Domain instead of the DNS Domain.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Chris DentPowerShell DeveloperCommented:

A bit late in the posting... but if you still need it...

If you have permission to access WMI this can get the domain name on a 200x machine:

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each objItem in colItems
      wscript.echo objItem.Domain
Next
0
 
rkogelheAuthor Commented:
Thanks Chris, but that also seems to return just "foo", not "foo.bar.com"...

I found a way around the problem for now. But it would still be nice to know how to do this. What we need is the "gethostbyname" that you find in Unix...
0
 
rkogelheAuthor Commented:
You'd figure that this should be in the MicrosoftDNS WMI, but I guess that wouldn't work if your DNS was provided by some other service.

After reading a bit on this, I think that this needs to do a reverse DNS lookup of the name using the IP address, then parse the name for the domain.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now