Gibt den Namen der Windows Domäne aus, an der sich der User angemeldet hat.
/// <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.");
}
Kommentare zum Snippet