473,842 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4697
How about the LOGONSERVER environment variable?

string server = Environment.Get EnvironmentVari able("LOGONSERV ER");

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.Get EnvironmentVari able("LOGONSERV ER");

Regards
Jeff

Marc Gravell wrote:
How about the LOGONSERVER environment variable?

string server = Environment.Get EnvironmentVari able("LOGONSERV ER");

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.Manageme nt;
using System.Windows. Forms;

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

foreach (ManagementObje ct queryObj in searcher.Get())
{

Console.WriteLi ne("-----------------------------------");
Console.WriteLi ne("Win32_Compu terSystem instance");

Console.WriteLi ne("-----------------------------------");
Console.WriteLi ne("DomainRole : {0}",
queryObj["DomainRole "]);
}
}
catch (ManagementExce ption 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.Get EnvironmentVari able("LOGONSERV ER");

Marc
Sep 16 '08 #4

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

Similar topics

4
19878
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 connection need an authentification. During the creation of a NetworkCredential you can define the login, the
1
2097
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 APS.NET WebApplication. "I tried aspnet_regiis.exe -i", I tried to re-install fw v1.1, but the account ASPNET won't get installed. Any suggestions? Thanks,
5
2759
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 Controler to listen to all new events and send them to a database. This last part I haven't worked on yet, cause I can't tell which events are relevant to write to the db and which are not. I have managed to listen to all the security log...
2
1664
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 environment. On the test environment the Web sServer is also PDC so there is no ASPNET account on this computer.
2
14952
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 but has anyone seen this before on a error page? I think it occured when users were reporting general slow web performance. I've seen it while users try to log into an NT domain from their desktops but not while using a web browser. Users can log...
0
1016
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 but works. Next step is to determine the types of the domains, i.e. is it a NT4 or an
1
5370
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. Ideally there would be something like,
2
1653
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
3619
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 option disable for SMB connection
0
9875
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9715
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10674
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7859
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7040
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5697
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5886
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4090
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3146
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.