1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
/// <summary>
/// Returns the name of the NT-Domain when the computer is member of a domain.
/// Throws an exception if the computer is not a member of a domain.
/// </summary>
/// <returns>Returns the full qualified name of the NT-Domain</returns>
public static string GetDomainName()
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_ComputerSystem");
foreach( ManagementObject queryObj in searcher.Get() )
{
return queryObj["Domain"].ToString();
}
} catch( Exception e )
{
throw new ManagementException("Error retrieving domain name.", e);
}
throw new ManagementException("Error retrieving domain name.");
}
|