473,412 Members | 2,277 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,412 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 4669
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...
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
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.