开发者

How to resolve the domain server name from .NET

开发者 https://www.devze.com 2023-01-23 00:40 出处:网络
Hi In a single server Wi开发者_高级运维ndows domain, does anyone know how to get the servername.

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

精彩评论

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