tags:

views:

19

answers:

2

Hi In a single server Windows domain, does anyone know how to get the servername. For example, in my test environment, we have a single Windows Small Business Server 2008 called horatio, it is the domain controller for longtest.local.

I have played around with the system.dns (with no positive results) :

    Dim myIP As IPHostEntry = Dns.GetHostEntry(My.Computer.Name)
    Dim IPAddress As String = myIP.AddressList.GetValue(0).ToString
    Dim myFullDomainName = Dns.GetHostEntry(IPAddress).HostName
    Dim DomainParts() As String = myFullDomainName.Split("."c)
    Dim DomainName As String = DomainParts(1)

However, I cannot seem to grab the servername, I need a function like :

GetDomainServer() that will return horatio (from the example above. Driving me a bit mad this one.

Regards Mark Harby Nottingham. UK

A: 

Ask the server. Like environment variable. The local machine name is available in one environment variable.

TomTom
TomTom, how does that help when I am trying to resolve the server name from a domain client ?
Mark Harby
+1  A: 

There's an environment variable called LOGONSERVER that you can use:

var domainServerName = Environment.GetEnvironmentVariable("LOGONSERVER");
klausbyskov
Brilliant, there's always a simple way. Thanks Klaus
Mark Harby