Diese Methode prüft, ob der Computer in einer Windows-NT Domäne ist, oder nur in einer Arbeitsgruppe
/// <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.");
}
Kommentare zum Snippet