473,378 Members | 1,577 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Determine the Primary Domain Controler

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
Sep 16 '08 #1
3 4663
How about the LOGONSERVER environment variable?

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

Marc
Sep 16 '08 #2
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

Marc Gravell wrote:
How about the LOGONSERVER environment variable?

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

Marc
Sep 16 '08 #3
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);
}
}
}
}

Marc Gravell wrote:
How about the LOGONSERVER environment variable?

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

Marc
Sep 16 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Prehaut Anselme | last post by:
Hi, I need to create a WebRequest with an automatic proxy I have the specification of this porxy (host & port) I ask the user their own login and password, but the proxy tells me that the...
1
by: Michael Maes | last post by:
Hello, I can't get the ASPNET-Account installed on a Windows 2000 (5.00.2195) Server SP4 Domain Controller. I always receive "Web Server not running ASP.NET version 1.1" when I try to start a...
5
by: Bruno Mendonça | last post by:
My boss asked me to build a program to create a report with logon/logoff events for all users within our windows domain. I'm using .Net to do so and decided to have a program running on the Domain...
2
by: Seb | last post by:
Hi All, I have a web page that tries to write in a xml file but I have an Access Denied error on the xml file. The page is working properly on the development computer but not on test...
2
by: Steve M | last post by:
A few users today received the message "The trust relationship between this workstation and the primary domain failed" on their web browser while using an ASP.NET web app. The problem went away...
0
by: Jan Wrage | last post by:
Hi! Currently i'm working on a program that should let u administer every domain on the network. First step is to enumerate all domains with DirectoryEntry("WinNT:") That takes a long time...
1
by: mark_aok | last post by:
Hi all, I have a situation where I need to determine a specific table's primary key, and then output it. I have tried the Database Object, and the Record Object, but I've had no luck. ...
2
by: Tuncer Erhamza | last post by:
Hi! Another web application (domain) call our application. We want to determine in our application which domain call. Thanks.
1
by: =?Utf-8?B?RW1lcmljIFRoaWJhdWQ=?= | last post by:
If I disable this option on Domain controler Policy : Microsoft Network Server: Digitally sign communications (always): DISABLE.Does it keep same security for All Windows XP client. Apple need this...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.