开发者

How to resolve the domain server name from .NET

Hi In a single server Wi开发者_高级运维ndows 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


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

var domainServerName = Environment.GetEnvironmentVariable("LOGONSERVER");


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜