How to determine whether the local machine is a domain contoller?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm writing a program which needs to determine whether the local machine is a
domain contoller or not. The steps I plan to do is:
1. Find out the local machine's name and domain name it belongs to.
2. Use System.DirectoryService to check whether the local machine is the
domain controller.

Question 1:
Is this the right way to do it? In other words, Is there a better/easier
way to do it?

Question 2:
How do I get the local machine's name and domain name? I can not use
System.Environment.UserDomainName to get the domain name because user may use
local account to login.

Thanks a lot,
Gniluy
 
Maybe you can use something like this:
System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName).HostName.IndexOf(".")

Normally, the machines not linked to a domain has no "." in its hostname
(but I don't ensure it totally).

HTH

Daniel Seara
 
Thanks. But System.Net.Dns.GetHostByName() just return the host name without
the domain name in my test environment even though my workstation is in a
domain.
 
Back
Top