I want to know if the computer is part of the Windows domain, you can get information about WMI Win32_NTDomain .
In powerShell, it gives:
Get-WmiObject Win32_NTDomain ClientSiteName : Default-First-Site-Name DcSiteName : Default-First-Site-Name Description : DOM DnsForestName : dom.fr DomainControllerAddress : \\192.168.183.100 DomainControllerName : \\WM2008R2ENT DomainName : DOM Roles : Status : OK
Edition according to @ScottTx comment you can also use the Win32_ComputerSystem WMI class
PS> (Get-WMIObject Win32_ComputerSystem).PartOfDomain False
According to the Win32_NTDomain Class Documentation in C # you can get it:
using System; using System.Collections.Generic; using System.Text; using System.Management; namespace WMIQuery { class WmiQuery { static void Main(string[] args) { ManagementObjectSearcher domainInfos = new ManagementObjectSearcher("select * from WIN32_NTDomain"); foreach (ManagementObject domainInfo in domainInfos.Get()) { Console.WriteLine("Name : {0}", domainInfo.GetPropertyValue("Name")); Console.WriteLine("Computer/domain : {0}", domainInfo.GetPropertyValue("Caption")); Console.WriteLine("Domain name : {0}", domainInfo.GetPropertyValue("DomainName")); Console.WriteLine("Status : {0}", domainInfo.GetPropertyValue("Status")); }
Adding a link to System.Management assembly
source share