To get current Domain of the PC in C# and VB.NET you can use the snippet below.
Sample C#
using System;
using System.DirectoryServices.ActiveDirectory;
namespace de.Fesslersoft.DomainTest
{
class Program
{
static void Main(string[] args)
{
var myDomain = Domain.GetComputerDomain();
foreach (DomainController dc in myDomain.DomainControllers)
{
Console.WriteLine("{0} - {1}", dc.IPAddress, dc.Name);
}
Console.Read();
}
}
}
Sample VB.NET
Imports System.DirectoryServices.ActiveDirectory
Namespace de.Fesslersoft.DomainTest
Class Program
Private Shared Sub Main(args As String())
Dim myDomain = Domain.GetComputerDomain()
For Each dc As DomainController In myDomain.DomainControllers
Console.WriteLine("{0} - {1}", dc.IPAddress, dc.Name)
Next
Console.Read()
End Sub
End Class
End Namespace
RT @CodeSnippetsNET: How to get current Domain of the PC in C# and #VB .NET http://t.co/xmlcXi8GjK #dotnet #csharp #programming #coding #co…
RT @CodeSnippetsNET: How to get current Domain of the PC in C# and #VB .NET http://t.co/xmlcXi8GjK #dotnet #csharp #programming #coding #co…
RT @CodeSnippetsNET: How to get current Domain of the PC in C# and #VB .NET http://t.co/xmlcXi8GjK #dotnet #csharp #programming #coding #co…
How to get current Domain of the PC in C# and #VBNET via @CodeSnippetsNET http://t.co/etm6lTLMLw #dotnet #csharp