How can I get the Workgroup name of a computer using C#?

delete picture delete · Apr 25, 2010 · Viewed 10k times · Source

I've read about getting it with the Environment class, but can't find it.

Thanks guys.

Answer

JoanComasFdz picture JoanComasFdz · Jun 6, 2011

A way based on the Jono response, but shorter:

public static string GetWorkGroup()
{
    ManagementObject computer_system = new ManagementObject(
                string.Format(
                "Win32_ComputerSystem.Name='{0}'",
                Environment.MachineName));

    object result = computer_system["Workgroup"];
    return result.ToString();
}