1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
/// <summary>
/// Determines wether the computer is member of a NT-Domain or not.
/// </summary>
/// <returns>Returns true if the computer is member of a NT-Domain, otherwise false</returns>
public static bool IsDomainMember()
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_ComputerSystem");
foreach( ManagementObject queryObj in searcher.Get() )
{
return bool.Parse(queryObj["PartOfDomain"].ToString());
}
} catch( Exception e )
{
throw new ManagementException("Error retrieving domain membership status.", e);
}
throw new ManagementException("Error retrieving domain membership status.");
}
|