Gibt den Namen der Windows Workgroup aus, in der sich der Computer befindet
/// <summary>
/// Returns the name of the workgroup when the computer is member of a workgroup.
/// Throws an exception if the computer is a member of a domain.
/// </summary>
/// <returns>Returns he full name of the workgroup</returns>
public static string GetWorkgroupName()
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_ComputerSystem");
foreach( ManagementObject queryObj in searcher.Get() )
{
return queryObj["Workgroup"].ToString();
}
} catch( Exception e )
{
throw new ManagementException("Error retrieving workgroup name.", e);
}
throw new ManagementException("Error retrieving workgroup name.");
}
Kommentare zum Snippet