Determine the Primary Domain Controler

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

Is there a way in C# to determine the Primary Domain Controller when a
users logs in on to a network.

I would prefer not to use WMI query method as this may not be available.

Regards
Jeff
 
How about the LOGONSERVER environment variable?

string server = Environment.GetEnvironmentVariable("LOGONSERVER");

Marc
 
Hi Marc

Tried this but this could be a BDC and not the PDC. Well that is what
happens in the network when I use
Environment.GetEnvironmentVariable("LOGONSERVER");

Regards
Jeff
 
I am looking for an alternative to this

Value Meaning
0 Standalone Workstation
1 Member Workstation
2 Standalone Server
3 Member Server
4 Backup Domain Controller
5 Primary Domain Controller


using System;
using System.Management;
using System.Windows.Forms;

namespace WMISample
{
public class MyWMIQuery
{
public static void Main()
{
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_ComputerSystem");

foreach (ManagementObject queryObj in searcher.Get())
{

Console.WriteLine("-----------------------------------");
Console.WriteLine("Win32_ComputerSystem instance");

Console.WriteLine("-----------------------------------");
Console.WriteLine("DomainRole: {0}",
queryObj["DomainRole"]);
}
}
catch (ManagementException e)
{
MessageBox.Show("An error occurred while querying for
WMI data: " + e.Message);
}
}
}
}
 
Back
Top