You can do this using WMI; add a link to System.Management.dll and a using statement for the System.Management namespace, then call the following code:
ManagementObjectSearcher mos =
new ManagementObjectSearcher (@ "root \ CIMV2", @ "SELECT * FROM Win32_ComputerSystem");
foreach (ManagementObject mo in mos.Get ()) {
Console.WriteLine (mo ["Workgroup"]);
} source
share