Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if machine is joined to domain?

Tags:

c#

.net

How do I detect whether the machine is joined to an Active Directory domain (versus in Workgroup mode)?

like image 823
DSO Avatar asked May 29 '09 14:05

DSO


People also ask

How can I tell if a computer is joined to a domain?

You can quickly check whether your computer is part of a domain or not. Open the Control Panel, click the System and Security category, and click System. Look under “Computer name, domain and workgroup settings” here. If you see “Domain”: followed by the name of a domain, your computer is joined to a domain.

How do you check if a machine is a domain controller?

Concluding. Using the DomainRole property of the ComputerSystem class is a useful and fast way to check whether a Server Core installation of Windows Server is a Domain Controller, whether it's domain-joined and whether it holds the PDCe FSMO role.

How can I tell if a Linux server is joined to a domain?

domainname command in Linux is used to return the Network Information System (NIS) domain name of the host. You can use hostname -d command as well to get the host domainname. If the domain name is not set up in your host then the response will be “none”.


1 Answers

Don't fool with pinvoke if you don't have to.

Reference System.DirectoryServices, then call:

System.DirectoryServices.ActiveDirectory.Domain.GetComputerDomain() 

Throws an ActiveDirectoryObjectNotFoundException if the machine is not domain-joined. The Domain object that's returned contains the Name property you're looking for.

like image 100
Joe Clancy Avatar answered Oct 12 '22 23:10

Joe Clancy