Determine the Primary Domain Controler

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
 
M

Marc Gravell

How about the LOGONSERVER environment variable?

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

Marc
 
J

Jeff

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
 
J

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);
}
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top