How to detect if machine is joined to domain?

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.

Leave a Comment