I've read about getting it with the Environment class, but can't find it.
Thanks guys.
I've read about getting it with the Environment class, but can't find it.
Thanks guys.
I'm thinking this could have been what you read:
System.Environment.GetEnvironmentVariable("USERDOMAIN")
But this has nothing to do with workgroup name. The workgroup name is not available in the environment (you could type "set" in a command prompt to verify that).
You can do this with WMI; add a reference to System.Management.dll and a using statement for 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"]); }