How do I detect whether the machine is joined to an Active Directory domain (versus in Workgroup mode)?
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.